How to use Response.AddHeader Method
-
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.
//Creating a datatable
DataTable Dtable = new DataTable("INFO");
//Adding a column of type string name URL
Dtable.Columns.Add("URL", typeof(string));
Dtable.Columns.Add("Files", typeof(string));
//putting files in an array of type string
string[] fileEntries = Directory.GetFiles(Server.MapPath("~/Uploads/"));
//int linkL = 0;
foreach (string fileName in fileEntries)
{
Dtable.Rows.Add("~/Uploads/" + Path.GetFileName(fileName));
//linkL++;
}myGrid.DataSource = Dtable; myGrid.DataBind();
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.
-
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.
//Creating a datatable
DataTable Dtable = new DataTable("INFO");
//Adding a column of type string name URL
Dtable.Columns.Add("URL", typeof(string));
Dtable.Columns.Add("Files", typeof(string));
//putting files in an array of type string
string[] fileEntries = Directory.GetFiles(Server.MapPath("~/Uploads/"));
//int linkL = 0;
foreach (string fileName in fileEntries)
{
Dtable.Rows.Add("~/Uploads/" + Path.GetFileName(fileName));
//linkL++;
}myGrid.DataSource = Dtable; myGrid.DataBind();
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.
Response.ContentType = this.FileContentType;
Response.AddHeader("Content-Disposition", "attachment; filename=" + this.FileName);If the filename has a space in it then either the whole filename should be quoted (and quotes in the string escaped). Or the entire filename should be encoded, which will use %20 to represent a space.
-
Response.ContentType = this.FileContentType;
Response.AddHeader("Content-Disposition", "attachment; filename=" + this.FileName);If the filename has a space in it then either the whole filename should be quoted (and quotes in the string escaped). Or the entire filename should be encoded, which will use %20 to represent a space.
-
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.
//Creating a datatable
DataTable Dtable = new DataTable("INFO");
//Adding a column of type string name URL
Dtable.Columns.Add("URL", typeof(string));
Dtable.Columns.Add("Files", typeof(string));
//putting files in an array of type string
string[] fileEntries = Directory.GetFiles(Server.MapPath("~/Uploads/"));
//int linkL = 0;
foreach (string fileName in fileEntries)
{
Dtable.Rows.Add("~/Uploads/" + Path.GetFileName(fileName));
//linkL++;
}myGrid.DataSource = Dtable; myGrid.DataBind();
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.
What, exactly, do you have against using the ASP.NET forum, which is where your posts belong?
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
-
What, exactly, do you have against using the ASP.NET forum, which is where your posts belong?
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
-
It doesn't matter what the language is, the problem is an ASP.NET one. So far, all your questions should have been asked there.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier