Archive for Settembre 25th, 2007

Create a comma delimited list

Settembre 25th, 2007

Description: This converts rows returned from a reader into a comma-delimited string.

Link: http://www.codekeep.net/snippets/07df10fa-37c2-4a2e-8bb1-b26c55cecc05.aspx

        private string GetCommaDelimitedList(IDataReader reader)
        {
            string list = string.Empty;
            StringBuilder sb = new StringBuilder();

            while (reader.Read())
                sb.AppendFormat(",{0}", reader[0]);

            if (sb.Length > 0)
                list = sb.ToString(1, sb.Length - 1);

            return list;
        }

Executing File Directory (The Correct Way)

Settembre 25th, 2007

Description: Often people will use Environment.CurrentDirectory to get what they think is the executing files directory. In reality, it is only sometimes the executing files directory. This shows the correct way to always get the executing files directory.

Link: http://www.codekeep.net/snippets/91510bc7-f9a9-41fd-9c9e-aa7c56dfa231.aspx

string correctPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);