我正在开发一个asp.net应用程序。它有以下方法:
private bool SaveDocumentFile(string FilePath, string FileName, byte[] Data)
{
BinaryWriter Writer = null;
string Name = "";
try
{
Name = FilePath + "\\" + FileName;
// Create a new stream to write to the file
Writer = new BinaryWriter(File.OpenWrite(Name));
// Writer raw data
Writer.Write(Data);
Writer.Flush();
Writer.Close();
}
catch (Exception ex)
{
Log.Error(ex.Message + " SaveDocumentFile Exception");
return false;
}
return true;
}
FileName参数可以是word,PDF或电子邮件格式。
如果文件名包含.msg扩展名,则字节数组将包含详细信息,例如from,to,email subject,email body等。函数将以.msg exension保存文件。如果我在outlook中打开已保存的文件,它将填充from,to,subject和body字段。
现在我想添加一个条件,以便每当文件格式为.msg时,SaveDocumentFile函数应该将存储在公共位置的文件夹中的附件添加到.msg文件中。
这可以实现吗?如果有,怎么样?任何帮助将不胜感激!
答案 0 :(得分:0)
使用MSG.NET(不是免费的)。请参阅add attachement tutorial。
using Independentsoft.Msg;
Message message = new Message("c:\\temp\\message.msg");
Attachment attachment = new Attachment("c:\\temp\\test.pdf");
message.Attachments.Add(attachment);
message.Save("c:\\temp\\message.msg", true);