.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

How to write to a text file in C#

Posted By: Kshitish     Posted Date: August 06, 2008    Points:2   Category :C#
I want to create a .txt file programatically and write some content into it. How can i do that using C#.

Kshitish

Responses
Author: Pankaj Mishra             
Posted Date: August 06, 2008     Points: 5   

Hi Kshitish,
To create file use FileStream class and use enumerator FileMode.OpenOrCreate or you can choose the enumerator.

eg.

FileStream fileStream = new FileStream(@"c:\file.txt", FileMode.OpenOrCreate);

StreamWriter streamWriter = new StreamWriter(fileStream);

streamWriter.BaseStream.Seek(0, SeekOrigin.End);
streamWriter.Write(" File Write Operation Starts : ");
streamWriter.Flush();
streamWriter.Close();



Cheers
Pankaj

Author: Rahul             
Posted Date: October 26, 2008     Points: 5   

Hi,
Refer this link

http://msdn.microsoft.com/en-us/library/6ka1wd3w.aspx

Author: Narayanan             
Posted Date: July 18, 2011     Points: 20   


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend