Reputation: 57
I have a module in ASP.NET C# that rename an uploaded file to a new one.
In case, if original file name is: thisisatext.txt
, when user uploaded into my server it will be renamed to TXT201302.TXT
.
All activities are recorded to database, with this structure:
| id | oldfilename | newfilename |
| 1 | thisisatext.txt | TXT201302.TXT |
Now I want to make a download module that rename uploaded file to their original filename, that is: thisisatext.txt
How can I do it?
Upvotes: 0
Views: 2546
Reputation: 17724
You have to set the file name in the Content-Disposition
http header
Response.AddHeader("Content-Disposition", "attachment; filename=" + oldfilename);
Response.ContentType = "text/plain";
Response.BinaryWrite(fileContents); //byte array contents of file
Response.End();
File will get downloaded, and user will be prompted to save it with the old file name.
Upvotes: 3