[英]Get XML file from email attachement to variable
因此,我希望能夠從電子郵件中獲取XML文件附件,並將其存儲在數據庫中以備后用。
我可以檢索電子郵件並將SenderEmailAdress,sentOn和正文存儲在數據庫中。 現在,我也想將XML文件附件添加到數據庫中,以便以后使用。
如何從電子郵件中獲取附件文件(或內容)並獲取變量,以便將其添加到數據庫中?
這是我現在擁有的附件的代碼(因此,在獲得郵件項之后):
//Check for attachments.
int AttachCnt = oMsg.Attachments.Count;
// Check if there are any attachments
if (AttachCnt > 0)
{
for (int i = 1; i <= AttachCnt; i++)
{
System.Diagnostics.Debug.WriteLine(i.ToString() + " - FileName: " + oMsg.Attachments[i].FileName);
String ext = Path.GetExtension(oMsg.Attachments[i].FileName);
// check if the file extention is .xml
if (ext == ".xml")
{
// Get the file ready to store in the DB. This is what I want to know!
return;
}
}
}
將附件另存為文件(Attachment.SaveAsFile),然后將文件數據讀入變量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.