Tuesday, February 15, 2011

How to convert Generic list into CSV format?

How to convert Generic list into CSV format?
        public static string ListToCSV<T>(List<T> list)
        {
            string output = null;

            foreach (System.Reflection.PropertyInfo info in typeof(T).GetProperties())
            {
                output += ((output==null)?"": ",")+ info.Name;
            }
            output += "\r\n";
            foreach (T t in list)
            {
                string oneline = null;
                foreach (System.Reflection.PropertyInfo info in typeof(T).GetProperties())
                {
                    oneline +=  ((info.GetValue(t, null)==null)?"": info.GetValue(t, null)) +   ",";
                }
                output += oneline + "\r\n";
            }
            return output;
        }

How to convert generic list (List) into datatable

How to convert generic list (List<t>) into datatable
        public static System.Data.DataTable ListToDataTable<T>(List<T> list)
        {
            DataTable table = new DataTable();
 
            foreach (System.Reflection.PropertyInfo info in typeof(T).GetProperties())
            {
                table.Columns.Add(new DataColumn(info.Name, info.PropertyType));
            }
            foreach (T t in list)
            {
                DataRow row = table.NewRow();
                foreach (System.Reflection.PropertyInfo info in typeof(T).GetProperties())
                {
                    row[info.Name] = info.GetValue(t, null);
                }
                table.Rows.Add(row);
            }
            return table;
        }

Monday, February 14, 2011

CDN for JQuery, Microsoft Vs. Google, which one is better

Almost same.

Micosoft:
http://www.asp.net/ajaxlibrary/cdn.ashx

<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.5.js" type="text/javascript"></script>
<script type="text/javascript">  </script>

Google CDN:
http://code.google.com/apis/libraries/devguide.html#jquery

Comparison:
Some of opinions in following article is out of date.
http://stackoverflow.com/questions/1447184/microsoft-cdn-for-jquery-or-google-cdn

A better open source project for zip file, DotNetZip

A better open source project for zip file, DotNetZip, http://dotnetzip.codeplex.com/
Feel better than SharpZipLib
http://www.sharpdevelop.net/OpenSource/SharpZipLib/

Sunday, February 13, 2011

Common performance issues on ASP.NET web sites

http://blogs.msdn.com/b/mcsuksoldev/archive/2011/01/19/common-performance-issues-on-asp-net-web-sites.aspx?cdn_id=2011-01-25-000