Altering File Names On Download
-
I have an upload section to a site I have built where users can upload whatever files they want. Upon upload a new name is created using a randon string generator and saved into one folder. The new name and the original name are then stored in a database. Simple The files are then displayed in a table on a page where the name of the link is the original name and the randon string name is the absolute link to the real file. This works fine but the file once downloaded comes with the random string as it's file name. How can I alter the name of the file back to it's original name when selected for download? I don't have access to IIS so this needs to be done in code on the fly? Many Thanks
-
I have an upload section to a site I have built where users can upload whatever files they want. Upon upload a new name is created using a randon string generator and saved into one folder. The new name and the original name are then stored in a database. Simple The files are then displayed in a table on a page where the name of the link is the original name and the randon string name is the absolute link to the real file. This works fine but the file once downloaded comes with the random string as it's file name. How can I alter the name of the file back to it's original name when selected for download? I don't have access to IIS so this needs to be done in code on the fly? Many Thanks
Can't you set the new name in the Content-Disposition header? Check out a quick example here: http://support.microsoft.com/kb/260519[^]
Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson -
Can't you set the new name in the Content-Disposition header? Check out a quick example here: http://support.microsoft.com/kb/260519[^]
Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis LevinsonYes I guess this is an option. This is exactly the same code that I use to output an Active Report to the user. It does of course invoke a postback though and additional processing. Can you see any issue with this? Any other options? Presumably I would need to load the file in my code into say a memory stream?
-
Yes I guess this is an option. This is exactly the same code that I use to output an Active Report to the user. It does of course invoke a postback though and additional processing. Can you see any issue with this? Any other options? Presumably I would need to load the file in my code into say a memory stream?
Sam Heller wrote:
I would need to load the file in my code into say a memory stream
How about response.writefile or response.transmitfile rather?
Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson -
Sam Heller wrote:
I would need to load the file in my code into say a memory stream
How about response.writefile or response.transmitfile rather?
Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis LevinsonHmm the original method you suggested seems to work fine. The only problem is I won't be able to do this from inside an update panel. Any suggestions?
-
Hmm the original method you suggested seems to work fine. The only problem is I won't be able to do this from inside an update panel. Any suggestions?
Further to this the content disposition method can't handle white space in the file name. I have been forced to run a quick replace to turn them all into underscores. Not ideal but I can live with it? Any suggestions to allow whitespace?
-
Further to this the content disposition method can't handle white space in the file name. I have been forced to run a quick replace to turn them all into underscores. Not ideal but I can live with it? Any suggestions to allow whitespace?
Sam Heller wrote:
the content disposition method can't handle white space in the file name
No. I think it takes it. Did you try escaping them and sending it to the web browser?
Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson -
Hmm the original method you suggested seems to work fine. The only problem is I won't be able to do this from inside an update panel. Any suggestions?
Sam Heller wrote:
update panel
AJAX control?
Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson -
Sam Heller wrote:
update panel
AJAX control?
Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis LevinsonYeah the ajax control known as the updatepanel. It doesn't allow the write though and errors.
-
Sam Heller wrote:
the content disposition method can't handle white space in the file name
No. I think it takes it. Did you try escaping them and sending it to the web browser?
Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis LevinsonHow would you escape the spaces in this way. If I have;
Response.AddHeader("content-disposition", "attachment; filename=" + ThisFile.FriendlyName)
Thanks