Home     Products      Support      Corporate     Sign In 
Support Knowledge Base, Article 1374
Product
FileUpEE
Version
5
Title
Cannot download file with "%" in the filename
Problem
When trying to download a file with a filename that contains a "%" followed by certain charaters (e.g. Test%5edcba.doc"), the file does not download. The server response gives error message: The specified file could not be found. Applies to FileUpEE and FileUpPE.
Solution

Note: This article discusses this issue in the contex of FileUpEE, but this information is valid for FileUpPE as well.

This issue originates from how .NET handles query strings in GET requests - not from XFile or FileUp.

The FileUpEE download samples make GET requests to the server and pass each file name as a parameter value in the query string of a request. The information is passed in a query string because there is a single FileUp page that receives information about each file to download. The query string of the request is URL encoded, which means that the file names are URL encoded as well. .NET automatically parses and decodes the query string before FileUpEE on the server gets the filename.

This means if the filenames contain characters that have special meaning in URL encoding, such as "%5e" (Unicode for "^") or "%ad" (Unicode for "-"), then .NET will decode the Unicode in the filename before FileUpEE receives the request. For instance, "Test%53Test.doc" will become "Test^Test.doc".

 

Suggestions

Suggestion #1: Use a database to store pairs and pass the fileID in the GET request instead of the file name.

If the end-users need to download files that contain URL encoding characters in the file names, then one way to get around this is to pass a file ID in the GET request instead of the file name. This approach would require:

  1. On the XFile download page (DownloadXFileNonVisual.aspx), in the Page_Load() event, instead of maintaining an ArrayList of the file paths, you would want a multi-dimensional array to keep track of the file paths and IDs.

  2. Also on the XFile download page, when the files are added to the XFile control, instead of passing the file name, you would pass the file ID instead:

    (JavaScript)
    //files[][] is the multi-dimensional array with file names and file ids
    //files[i,0] is the file name, files[i,1] is the file ID.
    XFile.AddFile(files[i, 0], serverURL + "?File=" + files[i, 1]);


    NOTE: XFile is not required, but whatever client-side component being used to make the GET requests to FileUpEE on the server should use a similar approach by passing file IDs in the query string instead of file names.

  3. In the server-side FileUp code (TwoTRDownloadWS.aspx.cs), in the DownloadFile() method. Then the file ID needs to be pulled from the query string. Finally, the file ID needs to be queried against the data base for the matching filename, before the file download request can be processed:

    (C#)
    private void DownloadFile()
    {
    string requestedFileName = "";
    int requestedFileID = Convert.ToInt(Request.QueryString["File"]); //Get the ID of the file to download
    
    //GetFileFromDatabase would be custom code to get the matching file name from the data base. 
    requestedFileName = GetFileNameFromDatabase(requestedFileID); 
    string downloadDirectory = Application["downloadDir"].ToString();
    ...
Suggestion#2: Avoid using URL encoding characters in filenames

If it's unlikely that end-users are going to be downloading files like "TestA^f13&%adf.doc", then there probably won't be many issues, except for maybe the "&" character, which can be handled through server-side code by changing how the query string is parsed (see this KB article).

For information about setting up FileUpEE or FileUpPE to handle Unicode character names in general, please see this KB article.

Created : 3/28/2011 5:28:26 PM (last modified : 3/28/2011 5:28:26 PM)
Rate this article!
Comments