Thursday, May 01, 2025

Breaking News
>> Securing and encrypt View State and Cookies values  >> Page has one or more controls that do not correspond with   >> “The Controls collection cannot be modified because the control contains code blocks”  >> How to fix "Validation(): Element 'xxxx' is not supported  >> How to create a new session in ASP.NET programmatically  >> MySQL Database Backup using mysqldump command    

Editors Picks

Tuesday, November 8, 2011

Writing a DataTable into a text file in asp.net c#


    public void Writewowfileintxt(DataTable dt, string filePath)
    {

        int i = 0;
        StreamWriter sw = null;
        try
        {
            TextInfo UsaTextInfo = new CultureInfo("en-US", false).TextInfo;
            sw = new StreamWriter(filePath, false);
            DataTable dtcolunm = clsd.getTablecolumn(tablename);
            for(i = 0; i < dt.Columns.Count - 1; i++)

                {

                    sw.Write(dt.Columns[i].ColumnName + ” | ”);

                }

                sw.Write(dt.Columns[i].ColumnName);

                sw.WriteLine();
            char[] charsToTrim = { ' ' };
            foreach (DataRow row in dt.Rows)
            {
                object[] array = row.ItemArray;
                for (i = 0; i < array.Length - 1; i++)
                {
       sw.Write(array[i].ToString);                       
                }
                sw.Write(array[i].ToString);
                sw.WriteLine();
            }
            sw.Close();
        }
        catch (Exception ex)
        {
        }
    }

No comments :

Post a Comment

Contact Us

Name

Email *

Message *