我将以下代码作为我的电子邮件附件代码。但它给我一个错误,我无法弄清楚来源。所有处置行都抛出错误,new Attachment(FileAttachment, MediaTypeNames.Application.Octet);
也是
if (FileAttachment != null){
// Create the file attachment for this e-mail message.
Attachment data = new Attachment(FileAttachment, MediaTypeNames.Application.Octet);
// Add time stamp information for the file.
ContentDisposition disposition = data.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(FileAttachment);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(FileAttachment);
disposition.ReadDate = System.IO.File.GetLastAccessTime(FileAttachment);
// Add the file attachment to this e-mail message.
AllMailMessage.Attachments.Add(data);
}
该行的#rorr消息"新附件(FileAttachment,MediaTypeNames.Application.Octet);"
Class System.Net.Mime.Media Typenames
specifies the media type information for email message attachment
Error:
The best overloaded method match for "System.Net.Mail.Attachment.Attachment..." has some invalid arguments
对于IO.File的三行,即System.IO.File.GetLastWriteTime(FileAttachment);
错误是相同的
The best overloaded method match for "System.IO.File...." has some invalid arguments
asp.Net文件上载代码
<td class="FileUpload">
<asp:FileUpload ID="FileAttachment" runat="server" />
</td>
答案 0 :(得分:1)
附件构造函数无法获取FileUpload
作为参数。它需要String
或Stream
。
您可以从FileContent
的{{1}}属性获取上传的文件流。
FileUpload
答案 1 :(得分:0)
问题是FileUpload
无法作为Attachment
类的参数
有关Attachment
您需要将Attachment
中的文件转换为要用作参数的流
答案 2 :(得分:0)
使用此...
mail.Attachments.Add(new Attachment(@"C:\ws_Log.txt"));