|Hi all, I am trying to change the name of each file as it's being downloaded. The following are what I have done thus far:
I have uploaded files to a folder on the web server but replace their names with GUIDs to prevent problems that could arise later on due to duplication . Their original names have been saved to a database and so are their extensions and the paths to their new location on the web server. The problem I am facing now is giving them their original names back when they are downloaded.
I know I have to replace the GUID with their original names and original extension when they are being downloaded. I have looked at using Response.AddHeader() method but I am not quite sure on how to make it work. Suppose a file in a folder on the web server have the GUID 123-GtR-XYZ as its name and suppose its original name was test.doc. How do I replace the GUID with the file's original name while it is being downloaded? The following is the method I currently use to retrieve a file from the folder on the web server.
DataTable Dtable = new DataTable("INFO");
string fileEntries = Directory.GetFiles(Server.MapPath("~/Uploads/"));
foreach (string fileName in fileEntries)
Dtable.Rows.Add("~/Uploads/" + Path.GetFileName(fileName));
myGrid.DataSource = Dtable;
Let's say that I have written a SQL query to retrieve the original file name and original extension of the file being downloaded and now we have the GUID, the original file name, and original extension. How do I make use of those data to give each downloaded file it's original name back? Please give a code snippet or point me to a good tutorial if you can. Thank you in advance for your help.
modified 14-Sep-12 1:12am.