如何在C#SmtpClient编程中设置带有中文字符的附件文件名? [英] How to set the attatchment file name with chinese characters in C# SmtpClient programming?

查看:210
本文介绍了如何在C#SmtpClient编程中设置带有中文字符的附件文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下:

  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?B?6IO955So5a6D5Zyo6ZmE5Lu25ZCN5Lit?= b

plz建议,如何在附件文件名中使用中文字符?

解决方案

可以尝试:

 附件att =新附件(@ c:文件的路径\somename.txt,
System.Net .Mime.MediaTypeNames.Application.Octet);

//这本身应该起作用。
att.Name =история-болезни.doc; //非英语文件名

//如果以上行没有使之起作用,请尝试此操作。
att.Name = System.Web.HttpUtility.UrlEncode(att.Name,System.Text.Encoding.UTF8);


my code is as below:

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

but the attachement received is not with the right chinese filename, and I found the ct.Name becames "=?utf-8?B?6L+Z5piv5LiA5Liq5b6I6ZW/55qE5Lit5paH5paH5Lu25ZCN5biM5pyb?=\r\n =?utf-8?B?6IO955So5a6D5Zyo6ZmE5Lu25ZCN5Lit?=" in the VS2010 debuger.

plz advice, how do I use the chinese charaters in attachment file name?

解决方案

Can you try:

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);

这篇关于如何在C#SmtpClient编程中设置带有中文字符的附件文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆