我的代码如下:

ContentType ct = new ContentType();
ct.MediaType = MediaTypeNames.Application.Octet;
ct.Name = "这是一个很长的中文文件名希望能用它在附件名中.Doc";
Attachment attach = new Attachment(stream, ct);


但收到的附件没有正确的中文文件名,我发现ct.Name变成了“ =?utf-8?B?6L + Z5piv5LiA5Liq5b6I6ZW / 55qE5Lit5paH5paH5Lu25ZCN5biM5pyb?= \ r \ n =?utf-8?BCN6BZ6Z5Z5Z6? VS2010调试器中的=“。

请注意,如何在附件文件名中使用中文字符?

最佳答案

你能试一下吗:

Attachment att = new Attachment(@"c:\path to file\somename.txt",
System.Net.Mime.MediaTypeNames.Application.Octet);

//this itself should work.
att.Name = "история-болезни.doc";  // non-english filename

//if the above line doesn't make it work, try this.
att.Name = System.Web.HttpUtility.UrlEncode(att.Name, System.Text.Encoding.UTF8);

08-03 21:59