0

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!

4

3 回答 3

1

您可以使用 System.IO.File.Exists(string path) 来确定它是否存在。如果是这样,您可以更改其名称并测试新名称是否已存在,直到您找到尚未使用的名称。

您可以在 msdn 上查看文档:http: //msdn.microsoft.com/en-us/library/system.io.file.exists.aspx

于 2013-04-09T12:25:19.150 回答
0

利用System.IO.File.Exists(string path)

于 2013-04-11T11:15:00.643 回答
0

如果要检查 SharePoint 文件,可以查看使用Microsoft.SharePoint.Client.Web方法GetFileByServerRelativeUrl(string serverRelativeUrl) GetFileByServerRelativeUrl

使用asp.net中的客户端对象模型从sharepoit库中获取sharepoint excel文件

一旦将文件从库加载到对象中,您可以进行!= null检查,如果文件不为空,则可以更改文件的名称。

于 2013-04-09T16:54:53.720 回答