Exemplo n.º 1
0
        private void AttachmentsToSPButton_Click(object sender, RibbonControlEventArgs e)
        {
            Inspector inspector = this.Context as Inspector;

            if (inspector == null)
            {
                throw new System.Exception("This is not an inspector window.");
            }
            Outlook.MailItem mailItem = inspector.CurrentItem as Outlook.MailItem;
            if (mailItem == null)
            {
                throw new System.Exception("This is not a mail item.");
            }

            if (EUSettingsManager.GetInstance().Settings.EmailAttachmentFolderUrl == String.Empty)
            {
                MessageBox.Show("Please set attachments folder first.");
                return;
            }
            string sourceFolder = EUSettingsManager.GetInstance().CreateATempFolder();
            List <EUEmailUploadFile> emailUploadFiles = new List <EUEmailUploadFile>();

            foreach (Attachment attachment in mailItem.Attachments)
            {
                string fileName                 = attachment.FileName;
                string extensionName            = String.Empty;
                string filenameWithoutExtension = String.Empty;
                if (fileName.LastIndexOf(".") > -1)
                {
                    extensionName            = fileName.Substring(fileName.LastIndexOf(".") + 1);
                    filenameWithoutExtension = fileName.Substring(0, fileName.LastIndexOf("."));
                }
                else
                {
                    filenameWithoutExtension = fileName;
                }
                string filePath = SharePointManager.GetUnuqieFileName(sourceFolder, filenameWithoutExtension, extensionName, out fileName);
                attachment.SaveAsFile(filePath);
                emailUploadFiles.Add(new EUEmailUploadFile(filePath, mailItem, null, false));
            }
//            string siteURL = SharePointManager.GetSiteURL(
            UploadAttachmentsProgressForm uploadAttachmentsProgressForm = new UploadAttachmentsProgressForm();
            EUSiteSetting siteSetting = EUSettingsManager.GetInstance().GetSiteSetting(EUSettingsManager.GetInstance().Settings.EmailAttachmentRootWebUrl);
            string        siteURL     = SharePointManager.GetSiteURL(siteSetting.Url, siteSetting);

            uploadAttachmentsProgressForm.Initialize(EUSettingsManager.GetInstance().Settings.EmailAttachmentWebUrl + "/" + EUSettingsManager.GetInstance().Settings.EmailAttachmentFolderUrl.TrimStart(new char[] { '/' }), sourceFolder, siteSetting, EUSettingsManager.GetInstance().Settings.EmailAttachmentRootFolderUrl, siteURL, EUSettingsManager.GetInstance().Settings.EmailAttachmentWebUrl, EUSettingsManager.GetInstance().Settings.EmailAttachmentListName, emailUploadFiles, mailItem);
            uploadAttachmentsProgressForm.ShowDialog();
//            SetSaveAttachmentsToSharePointButton();
        }
Exemplo n.º 2
0
        public static List <EUEmailUploadFile> GetEmailUploadFiles(List <Microsoft.Office.Interop.Outlook.MailItem> emailItems, DragEventArgs e, bool isListItemAndAttachmentMode, SaveFormatOverride saveFormatOverride) // JOEL JEFFERY 20110708 added SaveFormatOverride format
        {
            List <EUEmailUploadFile> emailUploadFiles = new List <EUEmailUploadFile>();
            string sourceFolder = EUSettingsManager.GetInstance().CreateATempFolder();

            if (e.Data.GetDataPresent("RenPrivateSourceFolder") == false)
            {
                MemoryStream memoryStream = (MemoryStream)e.Data.GetData("FileGroupDescriptor");
                memoryStream.Seek(76, SeekOrigin.Begin);

                byte[] fileName1 = new byte[256];
                memoryStream.Read(fileName1, 0, 256);

                System.Text.Encoding encoding = System.Text.Encoding.ASCII;
                string fileName = encoding.GetString(fileName1);
                fileName = fileName.TrimEnd(new char[] { '\0' });
                string extensionName            = String.Empty;
                string filenameWithoutExtension = String.Empty;
                CommonManager.GetFileNameAndExtension(fileName, out filenameWithoutExtension, out extensionName);
                string filePath = SharePointManager.GetUnuqieFileName(sourceFolder, filenameWithoutExtension, extensionName, out fileName);
                memoryStream = (MemoryStream)e.Data.GetData("FileContents");
                FileStream fs = new FileStream(filePath, FileMode.Create);
                memoryStream.WriteTo(fs);
                fs.Close();
                emailUploadFiles.Add(new EUEmailUploadFile(filePath, emailItems[0], null, isListItemAndAttachmentMode));
            }
            else
            {
                for (int i = 0; i < emailItems.Count; i++)
                {
                    Microsoft.Office.Interop.Outlook.MailItem item = emailItems[i] as Microsoft.Office.Interop.Outlook.MailItem;
                    if (item != null)
                    {
                        string subject = (item.Subject == null ? "Email Message" : item.Subject);
                        //if we are to upload the email as a .msg
                        if (saveFormatOverride == SaveFormatOverride.Email || (saveFormatOverride == SaveFormatOverride.None && EUSettingsManager.GetInstance().Settings.SaveAsWord == false && isListItemAndAttachmentMode == false)) // JOEL JEFFERY 20110708 added format == SaveFormatOverride check
                        {
                            string fileName = subject + ".msg";
                            string filePath = SharePointManager.GetUnuqieFileName(sourceFolder, item.Subject, "msg", out fileName);
                            item.SaveAs(filePath, OlSaveAsType.olMSG);
                            emailUploadFiles.Add(new EUEmailUploadFile(filePath, item, null, isListItemAndAttachmentMode));
                        }
                        else //if we are to upload the email as .doc and attachments
                        {
                            string fileName = String.Empty;
                            string filePath = SharePointManager.GetUnuqieFileName(sourceFolder, subject, "doc", out fileName);
                            item.SaveAs(filePath, OlSaveAsType.olDoc);
                            EUEmailUploadFile emailUploadFile = new EUEmailUploadFile(filePath, item, null, isListItemAndAttachmentMode, saveFormatOverride);
                            foreach (Attachment attachment in item.Attachments)
                            {
                                string extensionName            = String.Empty;
                                string filenameWithoutExtension = String.Empty;
                                CommonManager.GetFileNameAndExtension(attachment.FileName, out filenameWithoutExtension, out extensionName);
                                filePath = SharePointManager.GetUnuqieFileName(sourceFolder, filenameWithoutExtension, extensionName, out fileName);
                                attachment.SaveAsFile(filePath);
                                emailUploadFile.Attachments.Add(new EUEmailUploadFile(filePath, item, null, isListItemAndAttachmentMode, saveFormatOverride));
                            }
                            emailUploadFiles.Add(emailUploadFile);
                        }
                    }
                }
            }
            return(emailUploadFiles);
        }