HttpUtility. urlEncode converts null to the plus sign () in Encode, and converts the plus sign to null in Decode. However, the browser cannot understand that the plus sign is empty, so if the file name contains null, if the file downloaded from the browser is null, it becomes the plus sign. When developing pages using ASP. Net, we often use System. Web
HttpUtility. when UrlEncode is in Encode, it is converted to the plus sign (''). When Decode is used, the plus sign is converted to null, but the browser cannot understand that the plus sign is empty, therefore, if the file name contains null characters, the file downloaded from the browser becomes the plus sign. When developing pages using ASP. Net, we often use System. Web
HttpUtility. urlEncode converts a space into a plus sign ('+') in Encode, and converts the plus sign to a space in Decode. However, the browser cannot understand the plus sign as a space, therefore, if the file name contains spaces, the space of the file downloaded from the browser becomes the plus sign.
ASP. when developing pages, we often use System. web. httpUtility. urlEncode and UrlDecode PASS Parameters between pages through URLs. the use of Encode and Decode in pairs is correct. however, when writing a file download page, we often use the following method to specify the name of the downloaded file:
Response. AddHeader ("Content-Disposition", "attachment; filename =" + HttpUtility. UrlEncode (fileName, Encoding. UTF8 ));
The reason for conversion to UTF8 is to support Chinese file names.
At this time, the problem arises, because HttpUtility. urlEncode converts a space into a plus sign ('+') in Encode, and converts the plus sign to a space in Decode. However, the browser cannot understand the plus sign as a space, therefore, if the file name contains spaces, the space of the file downloaded from the browser becomes the plus sign.
One solution is to replace "+" with "% 20" after the UrlEncode of HttpUtility (if it is "+", it is converted to "% 2b"), for example:
FileName = HttpUtility. UrlEncode (fileName, Encoding. UTF8 );
FileName = fileName. Replace ("+", "% 20 ");