I'm currently developing an Outlook Addin which saves e-mail to sharepoint online, but before it saves them i need to check if a file with the same name already exists so it doesn't overwrite anything, here is the method which saves the file:
{
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.");
}
}
}
}
since I'm a beginner I lack the experience on how to go for this, Your help is sincerely appreciated, thanks to you all!