【发布时间】:2013-04-09 12:16:41
【问题描述】:
我目前正在开发一个 Outlook 插件,它将电子邮件保存到在线共享点, 但在保存它们之前,我需要检查是否已经存在同名文件,因此它不会覆盖任何内容,这是保存文件的方法:
{
currExplorer = OutlookApp.ActiveExplorer();
selection = currExplorer.Selection;
if (selection != null)
{
SharePointHelper spHelper = new SharePointHelper("LoginName", "Password", "Url/FolderDirectory");
if (selection.Count > 0)
{
for (int i = 1; i <= selection.Count; i++)
{
var item = selection[i] as Outlook.MailItem;
if (item == null)
continue;
// Check for attachments and save
currMail = item;
string fileName = String.Format("{0} - {1}.msg", SafeFileName(currMail.SenderName), SafeFileName(currMail.Subject));
string filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), fileName);
currMail.SaveAs(filePath, Outlook.OlSaveAsType.olMSG);
System.Net.HttpStatusCode status = spHelper.UploadFile(filePath, fileName);
if (status != System.Net.HttpStatusCode.Created)
MessageBox.Show(fileName + " failed to upload.");
}
}
}
}
由于我是初学者,我缺乏如何去做的经验, 衷心感谢您的帮助,谢谢大家!
【问题讨论】:
-
if (File.Exists(filename))... -
嗨,马修,这是否也适用于 SharePoint,因为我遇到了一些问题
标签: c# sharepoint outlook save filenames