Write Data into a Text File

Posted by Lakhangarg under ASP.NET category on | Views : 3205
Code to write Data into a text file:

private void GenerateTextFile()
string strHTMLContent = "My Name is Lakhan Pal Garg. \r\n I am a Senior Software Engineer. \r\n And i am Working in a Product Based Company.";
string attach = "attachment; filename=Lakhangarg.txt";
HttpContext.Current.Response.Charset = "";

HttpContext.Current.Response.ContentType = "application/text";
HttpContext.Current.Response.AddHeader("content-disposition", attach);

Comments or Responses

Posted by: Raja on: 8/25/2009 Level:Starter | Status: [Member]
The better way of manipulating text files in .net is described here


Posted by: Poster on: 8/26/2009 Level:Starter | Status: [Member]
Thanks Raja for pointing this out.

Posted by: Lakhangarg on: 8/26/2009 Level:Silver | Status: [Member] [Moderator]
Hi Raja ..

Thanks For Pointing out this... but i want to add one thing here.

in the above code it will show a popup to save the file s in this you can save file at any location instead of predefined hardcoded locatiion. Rest can you explain that how the that code is more optimize... i think that will more helpful for all to distinguish both piece of code..

Thanks & Regards
Lakhan Pal Garg

Login to post response