protected override List <UploadItem> SetUploadItemFilePath(string sourceFolder, string filePath, UploadItem uploadItem) { if (ConfigurationManager.GetInstance().Configuration.OutlookConfigurations.SaveAsWord&& Path.GetExtension(filePath) == ".msg") { List <UploadItem> additionalItems = new List <UploadItem>(); Microsoft.Office.Interop.Outlook.Application outlook = new Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.Interop.Outlook.MailItem mailItem = (Microsoft.Office.Interop.Outlook.MailItem)outlook.CreateItemFromTemplate(filePath); string newFileName = filePath.Substring(0, filePath.LastIndexOf('.')) + ".doc"; mailItem.SaveAs(newFileName, Microsoft.Office.Interop.Outlook.OlSaveAsType.olDoc); foreach (Microsoft.Office.Interop.Outlook.Attachment attachment in mailItem.Attachments) { string extensionName = String.Empty; string filenameWithoutExtension = String.Empty; string fileName = String.Empty; GetFileNameAndExtension(attachment.FileName, out filenameWithoutExtension, out extensionName); filePath = GetUnuqieFileName(sourceFolder, filenameWithoutExtension, extensionName, out fileName);//keep original name attachment.SaveAsFile(filePath); UploadItem attachmentItem = new UploadItem(); attachmentItem.Folder = uploadItem.Folder; attachmentItem.ContentType = uploadItem.ContentType; attachmentItem.FieldInformations = uploadItem.FieldInformations; attachmentItem.FilePath = filePath; additionalItems.Add(attachmentItem); } uploadItem.FilePath = newFileName; return(additionalItems); } else { base.SetUploadItemFilePath(sourceFolder, filePath, uploadItem); return(null); } }
public override void GetApplicationDragDropInformation(System.Windows.IDataObject data, out string[] filenames, out MemoryStream[] filestreams) { List <string> _fileNames = new List <string>(); List <MemoryStream> _filestreams = new List <MemoryStream>(); string sourceFolder = ConfigurationManager.GetInstance().CreateATempFolder(); Microsoft.Office.Interop.Outlook.Application application = Application as Microsoft.Office.Interop.Outlook.Application; for (int i = 1; i <= application.ActiveExplorer().Selection.Count; i++) { Object temp = application.ActiveExplorer().Selection[i]; if (temp is Microsoft.Office.Interop.Outlook.MailItem) { Microsoft.Office.Interop.Outlook.MailItem mailitem = (temp as Microsoft.Office.Interop.Outlook.MailItem); string fileName = mailitem.Subject + ".msg"; string invalid = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars()); foreach (char c in invalid) { fileName = fileName.Replace(c.ToString(), ""); } string filePath = sourceFolder + "\\" + fileName; mailitem.SaveAs(filePath); MemoryStream ms = new MemoryStream(); using (FileStream fs = File.OpenRead(filePath)) { fs.CopyTo(ms); } _fileNames.Add(fileName); _filestreams.Add(ms); } } filenames = _fileNames.ToArray(); filestreams = _filestreams.ToArray(); /* * //wrap standard IDataObject in OutlookDataObject * OutlookDataObject dataObject = new OutlookDataObject(data); * * try * { * //get the names and data streams of the files dropped * filenames = (string[])dataObject.GetData("FileGroupDescriptorW"); * filestreams = (MemoryStream[])dataObject.GetData("FileContents"); * } * catch (Exception ex) * { * string subject = ((string)dataObject.GetData("Text")).Split(new char[]{'\n'})[1].Split(new char[]{'\t'})[1]; * filenames = new string[]{subject}; * filestreams = new MemoryStream[] { (MemoryStream)dataObject.GetData("Object Descriptor") }; * } */ }