Skip to content

Creating text document in c#

jc mandapat

Asked Oct 8, 2006, 1:32 AM EDT1 answer
Share
LinkedInX
hi, does anyone know how to create a text document in c#? the data would probably come form a dataset, then i will save that to a text document. i've done it in VB but my code does not work in c#. any help will be much appreciated.Thanks guys!

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Hi this method used to read xml file in dataset ..that dataset field write in text file try this method. columns:name,Address1,Address2,Mobile PhysicalPath:"c:/MyTest/Sarav.txt" private void ReadXml() { try { string [email protected]("saravanan.xml"); FileStream fs=new FileStream(filePath,System.IO.FileMode.Open); ds.ReadXml(fs); DataGrid dg=new DataGrid(); dg.DataSource=ds; dg.DataBind(); this.Controls.Add(dg); //string [email protected]("da.txt"); //FileInfo fi=new FileInfo("c:/MyTest/Sarav.txt"); //FileStream fs1=fi.Open(FileMode.OpenOrCreate,FileAccess.Write); //create text file from dataset TextWriter tw=new StreamWriter("c:/MyTest/Sarav.txt"); foreach(DataRow dr in ds.Tables[0].Rows) { tw.WriteLine(dr["Name"].ToString()); tw.WriteLine(dr["Address1"].ToString()); tw.WriteLine(dr["Address2"].ToString()); tw.WriteLine(dr["Mobile"].ToString()); } tw.Close(); } catch(Exception Ex) { Ex.Message.ToString(); }
    0