I want to be able to create a text file and let the user save this to their own PC. Currently i have to do this:
StreamWriter sw;
sw = File.CreateText("C:\\results.txt");
Which obv saves on the web server but how can I replace that string with a link to their own computer? I looked at SaveFileDialog but it seems to only work for Windows Forms and not ASP sites, any advice?
Thanks in advance
You need to tell the Users Browser to Download the file. You can use the following code:
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType="text/plain";
Response.AppendHeader( "content-disposition", "attachment; filename=" + filename );
Response.AppendHeader( "content-length", fileContents.Length );
Response.BinaryWrite( fileContents );
Response.Flush();
Response.End();
Where fileContents is a byte[] of the files contents. and filename is the name of the file to suggest to the user.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With