Downloading documents with Response.AddHeader

Results 1 to 3 of 3

Thread: Downloading documents with Response.AddHeader

  1. #1
    Join Date
    Dec 1969

    Default Downloading documents with Response.AddHeader

    Hi,<BR><BR>I&#039;v got some problems with downloading files from my site. I offer a download of documents (MS Word, MS Excel...). So I use the AddHeader method of the Response object, e.g.:<BR><BR>Response.ContentType = "application/x-msexcel"<BR>Response.AddHeader("content-disposition","inline; filename=" + userFileName)<BR><BR>The filename is created by the user who wants to download the file and I don&#039;t want to restrain it to certain characters. But if the filename contains a ";" it is cut at this position and only the first part of the name is sent to the client. Because of that the suffix is cut off too and the client doesn&#039;t even know which application to open for the file. I&#039;ve tried to encode the special characters in the filename but then of course the name is sent that way to the client application which does no decoding. Using quotes does not help either. Maybe is there a possibility to add to the HTTP header without using the Response.AddHeader method where the semicolon is a separator?<BR><BR>A second question is that even if the filename does not include any semicolon, and the document is correctly opened in the client application, there is always a number in brackets added, for example, when the filename is "mySheet.xls" it is opened in MS Excel as "mySheet[1].xls". Does anybody know where this comes from?<BR><BR>I would be very grateful for any help.<BR><BR>Frank

  2. #2
    Join Date
    Dec 1969

    Default I think you'll find...

    ...that the semi-colon delimiter is part of the HTTP protocol, so you may have trouble getting around that.<BR><BR>You could try Server.URLEncode()-ing it and see if that helps.<BR><BR>As for the numbers, I think this is a browser thing...<BR><BR>Craig.

  3. #3
    Join Date
    Dec 1969

    Default It is a browser cache thing.

    If a file already exists in the cache, it adds [counter] to the filename to make them unique. There&#039;s really nothing you can do about that.<BR><BR>Secondly, PC&#039;s have a whole slew of characters that can&#039;t be in the filename. To find out what they are, go into Windows Explorer and try creating a file called "/i&#039;m a whore.txt". It will tell you what characters are invalid.<BR><BR>Your script needs to check for them. If any exist in the user&#039;s filename string - return an error. Do the same for a semi-colon if it isn&#039;t one of the characters that Windows doesn&#039;t allow.<BR><BR>-Doug

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts