unintelligible file name when using Response to download a file. VB.net

I have a website that shows a list of files stored in the server. Here is the code:

Dim ObjFileinfo As New FileInfo(strRootPath)

Response.Clear()

Response.AddHeader("Content-Disposition", "attachement;filename=" & strFileName)

'NOTE: strFile Name contains the name in Russian, if I Response.Write(strFileName)
'I get the proper Russian name displayed on the page so I am sure that I am passing the right one

Response.AddHeader("Content_Length", ObjFileinfo.Length.ToString())

Response.ContentType = "application/octet-stream"

Response.TransmitFile(strRootPath)

Response.End()

The problem is that when the files are written in Russian or Chinese the file name appears unintelligible written and when you click in "Save" the default name for the file is in those characters. E.g. a file called "просит.doc" appears as "просит.doc". If you open the file it appears OK and all the Russian characters are fine. It is just the name that it is messed up.Does anyone have an idea of why this is happening?  

error

Thanks,

Briega



 

0
briega
6/3/2008 3:24:11 PM
asp.net.web-forms 93655 articles. 3 followers. Follow

6 Replies
1313 Views

Similar Articles

[PageSpeed] 45

I have included a picture so you can understand what I am talking about.

Thanks,

Briega

0
briega
6/5/2008 11:08:35 AM

Hi briega,

I think you code seem to lack something.

Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename= & strFileName) 
Response.Charset = "UTF-8";
Response.ContentType = "application/vnd.ms-word";
Response.TransmitFile(strRootPath)
Response.End();

It will ok.

Let me know if I have misunderstood what you mean.
Thanks.
Hope it helps,
Hua Jun


Sincerely,
Hua Jun Li
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Hua
6/9/2008 7:24:28 AM

Hello Hua Jun,

I have changed the code but the name on the pop up window still appears unintelligible. Any other suggestion?

Thanks,

Manuel

0
briega
6/9/2008 8:32:59 AM

 Hi briega,

I am puzzled that I use the code I have give you, it is ok.

Do you use my code?

I think it is caused by the char encoding.

You can change another char encoding to try it.

Here is a article about it, you can read it.

http://msdn.microsoft.com/en-us/library/ms525304(VS.85).aspx

Let me know if I have misunderstood what you mean.
Thanks.
Hope it helps,
Hua Jun


Sincerely,
Hua Jun Li
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Hua
6/10/2008 2:15:25 AM

Hello Jua Jun,

This is the code I am using now:

Response.Clear()

Response.AddHeader(
"Content-Disposition", "attachment; filename=" + targetFile.Name)

Response.AddHeader("Content-Length", targetFile.Length.ToString)

Response.Charset = "UTF-8"

Response.ContentType = StrType

Response.TransmitFile(targetFile.FullName)

Response.End()

But the name still appears unintelligible.

Thanks,

Briega

0
briega
6/10/2008 10:50:32 AM

Hello Jua Jun,

The problem was in the "Content-Disposition" field, the name should be encoded. Here is the code that works:

Response.Clear()

Response.AddHeader(
"Content-Disposition", "attachment; filename=" & HttpUtility.UrlPathEncode(targetFile.Name))

Response.AddHeader("Content-Length", targetFile.Length.ToString)

Response.Charset = "UTF-8"

Response.ContentType = StrType

Response.TransmitFile(targetFile.FullName)

Response.End()

Here are some testing expiriences:

1. Using * adds the webpage name as the file name

2. Using UrlEncode adds + in the spaces

To display the file name as it is on the server I have used UrlPathEncode and it works not only for Russian but for other lenguages too.

Thanks for your help,

Briega

0
briega
6/10/2008 5:30:29 PM
Reply: