Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,

How can i create a text file in client system (C:\XXX\Config.txt)
when user click on Create Button on my WebPage, i am using
ASP.Net , C#.Net,

please help me.








Thanks
Sudheer.N
Posted

No you cannot write to the file in the client's machine. Its the security features. Any program executing in the browser executes within the browser sandbox and has access to limited features like printer, cookies etc.

But you cannot write to a file on user's machine. Somebody may use it to write a virus on user's machine. Its restricted.

Check this for a alternative solution..It writes the file as a "Response object" to the user's browser. The user has the choice whether to save it or not to his machine..

http://forums.asp.net/t/544299.aspx/1[^]
 
Share this answer
 
v3
Comments
Sudheer Nimmagadda 10-May-12 7:07am    
But i need to copy text file to Client System, please help me, we have some number of clients to for those i need to copy from my server to there local system when user click on Button
bbirajdar 10-May-12 7:59am    
Show me one website which does the task of writing files to the user's system and I will write the code for you..
bbirajdar 10-May-12 8:08am    
Even if you succeed in doing this through client side scripting or activex controls , the antivirus on the client's machine will now allow this code to execute
Sudheer Nimmagadda 10-May-12 9:11am    
Ok i agree with you, thank you very much
I don't think it is possible to write on a clients computer. You can save you data in cookies and use these cookies properly if you want to do something in logic using the data in file.

If your requirement is saving the file on disk then you will have to let the user know that he will have to download the file and save it in some location. you will have to provide the file to download in this case.
 
Share this answer
 
Comments
bbirajdar 10-May-12 8:02am    
I agree. My 5
Try the below code:

C#
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename="test.xls"");
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.Html32TextWriter oHtmlTextWriter = new System.Web.UI.Html32TextWriter(oStringWriter);
0Table.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();


This will give prompt the user to open or save test.xls file at the client side.

Edit: B Birajdar-Added the reference link
http://stackoverflow.com/questions/1072814/c-sharp-asp-net-write-file-to-client[^]
 
Share this answer
 
v2
Comments
Sudheer Nimmagadda 10-May-12 6:56am    
But User Need not to select Path, path is fixed for all clients like (C:\\Test\Config.txt")

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900