//in // folderPath: "\\\\[email protected]\\Inbox\\FTA\\Fabrikam" // folders" starting point to search below. // (Outlook.MAPIFolder)Globals.ThisAddIn.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); //out reference to MAPIFolder private Outlook.MAPIFolder GetFolder(string folderPath, Outlook.Folders folders) { if (folders == null) { Outlook.MAPIFolder inBox = (Outlook.MAPIFolder)Globals.ThisAddIn.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); folders = inBox.Folders; } string dir = folderPath.Substring(0, folderPath.Substring(4).IndexOf("\\") + 4); try { foreach (Outlook.MAPIFolder mf in folders) { if (!(mf.FullFolderPath.StartsWith(dir))) { continue; } if (mf.FullFolderPath == folderPath) { return(mf); } else { Outlook.MAPIFolder temp = GetFolder(folderPath, mf.Folders); if (temp != null) { return(temp); } } } return(null); } catch { return(null); } }
private void GetMailFolders(Outlook.Folders objInpFolders) { try { foreach (Outlook.Folder objFolder in objInpFolders) { if (objFolder.Folders.Count > 0) { lstOutlookFolders.Add(objFolder); GetMailFolders(objFolder.Folders); } else { lstOutlookFolders.Add(objFolder); } } } catch (Exception ex) { string strLog; strLog = "------------------" + System.DateTime.Now.ToString() + "-----------------\n"; strLog += "GetMailFolders method General Exception:" + "\n"; strLog += "Message:" + ex.Message + "\n"; strLog += "Source:" + ex.Source + "\n"; strLog += "StackTrace:" + ex.StackTrace + "\n"; strLog += "Data:" + ex.Data.ToString() + "\n"; strLog += "HResult:" + ex.HResult.ToString() + "\n"; strLog += "-------------------------------------------------------------------------" + "\n"; clsSuiteCRMHelper.WriteLog(strLog); ex.Data.Clear(); } }
private void GetMailFoldersHelper(Outlook.Folders objInpFolders, IList <Outlook.Folder> result) { try { foreach (Outlook.Folder objFolder in objInpFolders) { if (objFolder.Folders.Count > 0) { try { result.Add(objFolder); GetMailFoldersHelper(objFolder.Folders, result); } catch (COMException comx) { MessageBox.Show($"Failed to open mail folder {objFolder.Description} because {comx.Message}", "Failed to open mail folder", MessageBoxButtons.OK, MessageBoxIcon.Error); throw; } } else { result.Add(objFolder); } } } catch (Exception ex) { Log.Error("ThisAddIn.GetMailFolders", ex); ; } }
// outlook work private OutLook.MAPIFolder searchFolder(string folderName) { OutLook.NameSpace nameSpace = OutLookApp.GetNamespace("MAPI"); OutLook.Folders inboxSubfolders = Folder_Contacts.Folders; for (int i = 1; inboxSubfolders.Count >= i; i++) { OutLook.MAPIFolder subfolderInbox = inboxSubfolders[i]; if (subfolderInbox.Name == folderName) { try { return(subfolderInbox); } catch (COMException exception) { System.Windows.Forms.MessageBox.Show(exception.Message); } } if (subfolderInbox != null) { Marshal.ReleaseComObject(subfolderInbox); } } if (inboxSubfolders != null) { Marshal.ReleaseComObject(inboxSubfolders); } if (nameSpace != null) { Marshal.ReleaseComObject(nameSpace); } return(null); }
private void EnumerateFolders(Outlook.Folder folder, string prefix) { string diskFolder; Outlook.Folders childFolders = folder.Folders; if (childFolders.Count > 0) { foreach (Outlook.Folder childFolder in childFolders) { if (childFolder.DefaultItemType == Outlook.OlItemType.olMailItem) { if (Config.GetInstance().GetFoldersBinding().ContainsKey(childFolder.EntryID)) { diskFolder = Config.GetInstance().GetFoldersBinding()[childFolder.EntryID]; } else { diskFolder = ""; } var row = new Row(); row.Cells.Add(new Cell(prefix + childFolder.Name)); row.Cells.Add(new Cell(diskFolder)); row.Cells.Add(new Cell("...")); row.Tag = childFolder.EntryID; tableModel1.Rows.Add(row); // Call EnumerateFolders using childFolder. EnumerateFolders(childFolder, " " + prefix); } } } }
private Outlook.Folder EnumerateFolders(Outlook.Folder folder, string id) { if (folder.EntryID == id) { return(folder); } Outlook.Folders childFolders = folder.Folders; if (childFolders.Count > 0) { foreach (Outlook.Folder childFolder in childFolders) { if (childFolder.DefaultItemType == Outlook.OlItemType.olMailItem) { // Call EnumerateFolders using childFolder. var f = EnumerateFolders(childFolder, id); if (f != null && f.EntryID == id) { return(f); } } } } return(null); }
private void CreateHtmlFolder() { Outlook.MAPIFolder newView = null; string viewName = "HtmlView"; Outlook.MAPIFolder inBox = (Outlook.MAPIFolder) this.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook .OlDefaultFolders.olFolderInbox); Outlook.Folders searchFolders = (Outlook.Folders)inBox.Folders; bool foundView = false; foreach (Outlook.MAPIFolder searchFolder in searchFolders) { if (searchFolder.Name == viewName) { newView = inBox.Folders[viewName]; foundView = true; } } //Outlook.OlDefaultFolders.olFolderInbox if (!foundView) { newView = (Outlook.MAPIFolder)inBox.Folders. Add("HtmlView", Outlook.OlDefaultFolders.olFolderInbox); newView.WebViewURL = "https://www.microsoft.com"; newView.WebViewOn = true; } Application.ActiveExplorer().SelectFolder(newView); Application.ActiveExplorer().CurrentFolder.Display(); }
private void ProcessFolders(AppContext ctx, Outlook.Folders folders) { foreach (Outlook.MAPIFolder folder in folders) { ProcessFolder(ctx, folder); } }
private ObjOutlook.MAPIFolder GetFolder(ObjOutlook.Folders ReadFold, string name) { ObjOutlook.MAPIFolder TempStr = null; foreach (ObjOutlook.MAPIFolder MovFold in ReadFold) { if (MovFold.Name == name) { TempStr = MovFold; } if (MovFold.Folders.Count > 0) { ObjOutlook.MAPIFolder TempStr2 = null; TempStr2 = GetFolder(MovFold.Folders, name); if (TempStr2 != null) { TempStr = TempStr2; } } } return(TempStr); }
// Returns Folder object based on folder path static Outlook.Folder GetFolder(string folderPath) { Console.WriteLine("Looking for: " + folderPath); Outlook.Folder folder; string backslash = @"\"; try { if (folderPath.StartsWith(@"\\")) { folderPath = folderPath.Remove(0, 2); } String[] folders = folderPath.Split(backslash.ToCharArray()); Outlook.Application Application = new Outlook.Application(); folder = Application.Session.Folders[folders[0]] as Outlook.Folder; if (folder != null) { for (int i = 1; i <= folders.GetUpperBound(0); i++) { Outlook.Folders subFolders = folder.Folders; folder = subFolders[folders[i]] as Outlook.Folder; if (folder == null) { return(null); } } } return(folder); } catch (Exception ex) { Console.WriteLine(ex.Message); return(null); } }
private void GetMailFolders(Outlook.Folders folders, TreeNodeCollection nodes, ISet <string> selectedFolderEntryIds) { try { foreach (Outlook.Folder objFolder in folders) { var objNode = new TreeNode() { Tag = objFolder.EntryID, Text = objFolder.Name }; if (selectedFolderEntryIds.Contains(objFolder.EntryID)) { objNode.Checked = true; } nodes.Add(objNode); var nestedFolders = objFolder.Folders; if (nestedFolders.Count > 0) { GetMailFolders(nestedFolders, objNode.Nodes, selectedFolderEntryIds); } } } catch (Exception ex) { // Swallow exception(!) ErrorHandler.Handle("Failed while getting email folders", ex); } }
static Outlook.Folder getFolder(string folderPath) //Gets the Inbox folder and confines the program search only within it. { Outlook.Folder folder; string backslash = @"\"; try { if (folderPath.StartsWith(@"\\")) //The folder path is the name of the folder configured in outlook, which is the userName. Uncomment the blow two lines and run to understand what is the folderPath here. { folderPath = folderPath.Remove(0, 2); } String[] folders = folderPath.Split(backslash.ToCharArray()); //folders[] array contains the userNames configured in outlook as folders. Outlook.Application Application = new Outlook.Application(); folder = Application.Session.Folders[folders[0]] as Outlook.Folder; Outlook.Folders subfolders = folder.Folders; for (int i = 1; i <= subfolders.Count; i++) { if (subfolders[i].Name.Contains("Inbox")) { folder = (Outlook.Folder)subfolders[i]; } } return(folder); //Returns the inbox folder } catch (Exception e) { generalExceptions(e); return(null); } }
private void GetMailFolders(EmailAccountsArchiveSettings settings, Outlook.Folders folders) { this.tsResults.Nodes.Clear(); this.tsResults.CheckBoxes = true; GetMailFolders(folders, tsResults.Nodes, settings.SelectedFolderEntryIds); this.tsResults.ExpandAll(); }
private IEnumerable <Outlook.Folder> GetMailFolders(Outlook.Folders root) { var result = new List <Outlook.Folder>(); GetMailFoldersHelper(root, result); return(result); }
//public MAPIFolder GetFolder(MAPIFolder folder, string FullFolderPath) //{ // if (folder.Folders.Count == 0) // { // if (folder.FullFolderPath == FullFolderPath) // { // return folder; // } // } // else // { // foreach (MAPIFolder subFolder in folder.Folders) // { // if (folder.FullFolderPath == FullFolderPath) // { // return folder; // } // var temp = GetFolder(subFolder, FullFolderPath); // if (temp != null) return temp; // } // } // return null; //} //public MAPIFolder GetFolder(NameSpace folder, string FullFolderPath) //{ // foreach (MAPIFolder subFolder in folder.Folders) // { // var temp = GetFolder(subFolder, FullFolderPath); // if (temp != null) return temp; // } // return null; //} private Microsoft.Office.Interop.Outlook.Folder GetFolder(Application application, string folderPath) { Microsoft.Office.Interop.Outlook.Folder folder; string backslash = @"\"; try { if (folderPath.StartsWith(@"\\")) { folderPath = folderPath.Remove(0, 2); } String[] folders = folderPath.Split(backslash.ToCharArray()); folder = application.Session.Folders[folders[0]] as Microsoft.Office.Interop.Outlook.Folder; if (folder != null) { for (int i = 1; i <= folders.GetUpperBound(0); i++) { Microsoft.Office.Interop.Outlook.Folders subFolders = folder.Folders; folder = subFolders[folders[i]] as Microsoft.Office.Interop.Outlook.Folder; if (folder == null) { return(null); } } } return(folder); } catch { return(null); } }
private void EnumerateFolders(Outlook.Folders folders, Folder rootFolder) { foreach (Outlook.MAPIFolder f in folders) { // ensure it's a folder that contains mail messages (i.e. no contacts, appointments, etc.) if (f.DefaultItemType == Outlook.OlItemType.olMailItem) { if (rootFolder.Folders == null) { rootFolder.Folders = new List <Folder>(); } // add the current folder and enumerate all sub-folders Folder subFolder = new Folder(f.EntryID, f.Name, f.UnReadItemCount, f.Items.Count); rootFolder.Folders.Add(subFolder); if (f.Folders.Count > 0) { this.EnumerateFolders(f.Folders, subFolder); } } } // alphabetize the list (Folder implements IComparable) rootFolder.Folders.Sort(); }
/// <summary> /// Получение папки по пути к ней /// </summary> /// <param name="folderPath"></param> /// <returns></returns> private Outlook.Folder GetFolder(string folderPath) { Outlook.Folder folder; string backslash = @"\"; try { if (folderPath.StartsWith(@"\\")) { folderPath = folderPath.Remove(0, 2); } String[] folders = folderPath.Split(backslash.ToCharArray()); folder = OutlookApp.Application.Session.Folders[folders[0]] as Outlook.Folder; if (folder != null) { for (int i = 1; i <= folders.GetUpperBound(0); i++) { Outlook.Folders subFolders = folder.Folders; folder = subFolders[folders[i]] as Outlook.Folder; if (folder == null) { return(null); } } } return(folder); } catch (Exception ex) { MessageBox.Show(ex.Message); return(null); } }
private void PopulateFolders(Outlook.Folders folders, List <Outlook.MAPIFolder> folderList) { foreach (Outlook.MAPIFolder folder in folders) { folderList.Add(folder); PopulateFolders(folder.Folders, folderList); } }
private static void GetSubFolders(OutLook.Folders folders) { foreach (OutLook.MAPIFolder f in folders) { Console.WriteLine(f.Name); GetSubFolders(f.Folders); } }
static void Main(string[] args) { var toAddress = (string)null; if (args.Length > 0) { toAddress = args[0]; } try { oOutlook = OutlookHelper.GetApplicationObject(); Outlook.Folders folders = oOutlook.Session.Folders; List <HeadsUpItem> returnItems = new List <HeadsUpItem>(); ProcessFolder((Outlook.Folder)oOutlook.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar), returnItems); ProcessFolder((Outlook.Folder)oOutlook.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks), returnItems); StringBuilder htmlText = new StringBuilder(); htmlText.Append("<HEAD>" + "<STYLE TYPE=\"text/css\">" + "<!--" + "BODY" + " {" + " font-family:sans-serif;" + " font-size: 10px;" + " }" + "B" + " {" + " font-family:sans-serif;" + " font-size: 10px;" + " font-style: Bold;" + " }" + "-->" + "</STYLE>" + "</HEAD>"); for (int i = 0; i < 7; i++) { AppendHeadsUp(htmlText, returnItems, DateTime.Now.AddDays(i).Date); } Outlook.MailItem newMail = oOutlook.CreateItem(Outlook.OlItemType.olMailItem); if (toAddress == null) { toAddress = GetCurrentUserEmailAddress(); } newMail.To = toAddress; newMail.Subject = "Heads Up!"; newMail.HTMLBody = htmlText.ToString(); //newMail.SaveSentMessageFolder = (Outlook.Folder)oOutlook.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); newMail.Send(); } catch (ApplicationException e) { Console.WriteLine("ERROR: " + e.Message); } // Console.Read(); }
/// <summary> /// Uses recursion to list all folders from an initial fodler and list /// </summary> /// <param name="folder">The folder from which to extract the subfolders</param> /// <param name="folders">The list into which list the folders</param> private void ListFolders(Outlook.Folder folder, ref List <Folder> folders) { Outlook.Folders childFolders = folder.Folders; foreach (Outlook.Folder childFolder in childFolders) { folders.Add(new Folder(childFolder)); ListFolders(childFolder, ref folders); } }
void BindToRunningProcessesOutlook() { // Get the current process. Process currentProcess = Process.GetCurrentProcess(); // Get all processes running on the local computer. Process[] localAll = Process.GetProcessesByName("OUTLOOK"); foreach (var pr in localAll) { Console.WriteLine(pr.Id + " - " + pr.ProcessName + " " + pr.HandleCount); //Console.WriteLine(pr.Id + " - " + pr.ProcessName ); try { Console.WriteLine(" ", pr.MainModule.ModuleName); } catch (Exception ex) {; } } Outlook.Application application; if (localAll.Length > 0) { application = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application; } else { application = new Outlook.Application(); } Console.WriteLine(application.Explorers.Count); Outlook.Folder root = application.Session.DefaultStore.GetRootFolder() as Outlook.Folder; Outlook.Folders childFolders = root.Folders; Console.WriteLine(childFolders.Count); foreach (Outlook.Folder fld in childFolders) { Console.WriteLine(" " + fld.Name); if (fld.Name == "Inbox") { foreach (Outlook.Folder finbox in fld.Folders) { Console.WriteLine(" " + finbox.Name); } Outlook.Items it = fld.Items.Restrict("[MessageClass]='IPM.Note'"); for (int i = 1; i <= it.Count; i++) { Console.WriteLine(it[i].Subject); } } } Console.ReadKey(); }
void AddTree(TreeNodeCollection nodes, Outlook.Folders folders) { for (int i = 1; i <= folders.Count; ++i) { TreeNode child = new OFTreeNode(folders[i].Name, folders[i]); AddTree(child.Nodes, folders[i].Folders); nodes.Add(child); } }
//only searches one level deep! private void searchFolder(string query, Outlook.Folders folders) { if (folders == null) { Outlook.MAPIFolder inBox = (Outlook.MAPIFolder)Globals.ThisAddIn.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); folders = inBox.Folders; } Hashtable res = new Hashtable(); foreach (Outlook.MAPIFolder folder in folders) { if (folder.Name.ToLower().Contains(query)) { res[folder.Name] = folder.FolderPath; } } switch (res.Keys.Count) { case 0: writeError("Folder not found"); //searchButton.Image = new Bitmap(Properties.Resources.foundNot); break; case 1: //there's only 1, but not sure if there's a better way to get it. foreach (string key in res.Keys) { folderBox.Text = key; folderBox.Tag = res[key]; moveButton.Enabled = true; moveOptions.Enabled = false; //searchButton.Image = new Bitmap(Properties.Resources.foundOk); } break; default: moveOptions.Enabled = true; moveButton.Enabled = false; moveOptions.Items.Clear(); //clearing the field triggers the folderBox_TextChanged option as well! //folderBox.Text = null; //searchButton.Image = new Bitmap(Properties.Resources.foundOk); foreach (string key in res.Keys) { RibbonDropDownItem item = Globals.Factory.GetRibbonFactory().CreateRibbonDropDownItem(); item.Label = key; item.Tag = res[key]; moveOptions.Items.Add(item); } break; } }
private static void EnumerateFolders(Outlook.Folder folder, List <Outlook.Folder> folders) { Outlook.Folders childFolders = folder.Folders; if (childFolders.Count > 0) { foreach (Outlook.Folder childFolder in childFolders) { folders.Add(childFolder); EnumerateFolders(childFolder, folders); } } }
/// <summary> /// Finds the subfolder matching the given name /// </summary> /// <param name="name">The name of the subfolder to match</param> /// <returns>The folder</returns> public Folder GetDirectChild(string name) { Outlook.Folders childFolders = folder.Folders; foreach (Outlook.Folder childFolder in childFolders) { if (childFolder.Name == name) { return(new Folder(childFolder)); } } return(null); }
private void VerificaSubpastas(Outlook.Folder folder) { Outlook.Folders subPastas = folder.Folders; if (subPastas.Count > 0) { foreach (Outlook.Folder subPasta in subPastas) { CheckedListBoxPastas.Items.Add(subPasta.Name); pastasEmailSelecionado.Add(subPasta); VerificaSubpastas(subPasta); } } }
private void DisableAddIn() { Application.NewMailEx -= Application_NewMailEx; sentboxItems.ItemAdd -= Items_ItemAdd; Application.AdvancedSearchComplete -= Application_AdvancedSearchComplete; inbox = null; sentboxItems = null; sentbox = null; rules = null; searchFolders = null; defaultNamespace = null; }
private bool FolderExists(string folderName, Outlook.Folders foldersColl) { try { var foo = foldersColl[folderName] as Outlook.MAPIFolder; return(true); // folder exists } catch { // folder does not exist } return(false); }
private void EnumerateFolders(Outlook.Folder folder) { Outlook.Folders childFolders = folder.Folders; if (childFolders.Count > 0) { foreach (Outlook.Folder childFolder in childFolders) { lstOutlookDirs.Add(childFolder.FolderPath); EnumerateFolders(childFolder); } } }
/// <summary> /// Constructor. Initiated from MailFolder objects /// </summary> /// <param name="folders">Outlook.Folders object</param> public MailFolders(Outlook.Folders folders) { _folders = folders; }
/// <summary> /// code written by Joy /// excutes ansd the start the timer upload process when the backgoundworkers's do work event fires /// </summary> /// <param name="Item"></param> void doBackGroundUpload(object Item) { try { Globals.ThisAddIn.isTimerUploadRunning = true; OutlookObj = Globals.ThisAddIn.Application; outlookNameSpace = OutlookObj.GetNamespace("MAPI"); Outlook.MAPIFolder oInBox = outlookNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); Outlook.MAPIFolder olMailRootFolder = (Outlook.MAPIFolder)oInBox.Parent; oMailRootFolders = olMailRootFolder.Folders; Outlook.MailItem moveMail = (Outlook.MailItem)Item; string newCatName = "Successfully Uploaded"; if (Globals.ThisAddIn.Application.Session.Categories[newCatName] == null) { outlookNameSpace.Categories.Add(newCatName, Outlook.OlCategoryColor.olCategoryColorDarkGreen, Outlook.OlCategoryShortcutKey.olCategoryShortcutKeyNone); } XmlNode uploadFolderNode = UserLogManagerUtility.GetSPSiteURLDetails("", folderName); if (uploadFolderNode != null) { bool isDroppedItemUplaoded = false; addinExplorer = ThisAddIn.OutlookObj.ActiveExplorer(); //Check the folder mapping with documnet library if (isUserDroppedItemsCanUpload == false) { //Show message try { Outlook.MailItem m = (Outlook.MailItem)Item; mailitemEntryID = m.EntryID; try { mailitem = m; mailitemEntryID = m.EntryID; string strsubject = m.EntryID; if (string.IsNullOrEmpty(strsubject)) { strsubject = "tempomailcopy"; } mailitemEntryID = strsubject; string tempFilePath = UserLogManagerUtility.RootDirectory + "\\" + strsubject + ".msg"; if (Directory.Exists(UserLogManagerUtility.RootDirectory) == false) { Directory.CreateDirectory(UserLogManagerUtility.RootDirectory); } m.SaveAs(tempFilePath, Outlook.OlSaveAsType.olMSG); } catch (Exception ex) { } Outlook.MAPIFolder fp = (Outlook.MAPIFolder)m.Parent; DoNotMoveInNonDocLib(mailitemEntryID, fp); } catch (Exception) { NonDocMoveReportItem(Item); } MessageBox.Show("You are attempting to move files to a non document library. This action is not supported.", "ITOPIA", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (frmUploadItemsListObject == null || (frmUploadItemsListObject != null && frmUploadItemsListObject.IsDisposed == true)) { //frmUploadItemsListObject = new frmUploadItemsList(); // myCustomTaskPane = Globals.ThisAddIn.CustomTaskPanes.Add(frmUploadItemsListObject, "ITOPIA"); //myCustomTaskPane.Visible = true; IAddCustomTaskPane(); } //frmUploadItemsListObject.TopLevel = true; //frmUploadItemsListObject.TopMost = true; ////////////////////// frmUploadItemsListObject.Show(); try { ////// ////////// Outlook.MailItem oMailItem = (Outlook.MailItem)Item; parentfolder = (Outlook.MAPIFolder)oMailItem.Parent; try { mailitem = oMailItem; mailitemEntryID = oMailItem.EntryID; string strsubject = oMailItem.EntryID; if (string.IsNullOrEmpty(strsubject)) { strsubject = "tempomailcopy"; } mailitemEntryID = strsubject; string tempFilePath = UserLogManagerUtility.RootDirectory + "\\" + strsubject + ".msg"; if (Directory.Exists(UserLogManagerUtility.RootDirectory) == false) { Directory.CreateDirectory(UserLogManagerUtility.RootDirectory); } oMailItem.SaveAs(tempFilePath, Outlook.OlSaveAsType.olMSG); } catch (Exception ex) { } string fileName = string.Empty; if (!string.IsNullOrEmpty(oMailItem.Subject)) { //Replce any specila characters in subject fileName = Regex.Replace(oMailItem.Subject, strMailSubjectReplcePattern, " "); fileName = fileName.Replace(".", "_"); } if (string.IsNullOrEmpty(fileName)) { DateTime dtReceivedDate = Convert.ToDateTime(oMailItem.ReceivedTime); fileName = "Untitled_" + dtReceivedDate.Day + "_" + dtReceivedDate.Month + "_" + dtReceivedDate.Year + "_" + dtReceivedDate.Hour + "_" + dtReceivedDate.Minute + "_" + dtReceivedDate.Millisecond; } UploadItemsData newUploadData = new UploadItemsData(); newUploadData.ElapsedTime = DateTime.Now; newUploadData.UploadFileName = fileName;// oMailItem.Subject; newUploadData.UploadFileExtension = ".msg"; newUploadData.UploadingMailItem = oMailItem; newUploadData.UploadType = TypeOfUploading.Mail; newUploadData.DisplayFolderName = folderName; frmUploadItemsListObject.UploadUsingDelegate(newUploadData); //Set dropped items is uploaded /////////////////////////updated by Joy on 25.07.2012///////////////////////////////// bool uploadStatus = frmUploadItemsListObject.IsSuccessfullyUploaded; XMLLogOptions userOption = UserLogManagerUtility.GetUserConfigurationOptions(); if (uploadStatus == true) { // Globals.ThisAddIn.isTimerUploaded = true; isDroppedItemUplaoded = true; for (int i = 0; i <= activeDroppingFolder.Items.Count; i++) { try { Outlook.MailItem me = (Outlook.MailItem)activeDroppingFolder.Items[i]; if (me.EntryID == mailitemEntryID) { me.Categories.Remove(0); me.Categories = newCatName; me.Save(); if (userOption.AutoDeleteEmails == true) { UserMailDeleteOption(mailitemEntryID, parentfolder); } } } catch (Exception ex) { } } frmUploadItemsListObject.lblPRStatus.Invoke(new updateProgresStatus(() => { frmUploadItemsListObject.lblPRStatus.Text = Globals.ThisAddIn.no_of_t_item_uploaded.ToString() + " " + "of" + " " + Globals.ThisAddIn.no_of_pending_items_to_be_uploaded.ToString() + " " + "Uploaded"; })); frmUploadItemsListObject.progressBar1.Invoke(new updateProgessBar(() => { frmUploadItemsListObject.progressBar1.Value = (((Globals.ThisAddIn.no_of_t_item_uploaded * 100 / Globals.ThisAddIn.no_of_pending_items_to_be_uploaded))); })); } else { isDroppedItemUplaoded = false; } /////////////////////////updated by Joy on 25.07.2012///////////////////////////////// } catch (Exception ex) { isDroppedItemUplaoded = MoveItemIsReportItem(Item); } try { if (isDroppedItemUplaoded == false) { //string tempName = oDocItem.Subject; string tempName = string.Empty; Outlook.DocumentItem oDocItem = (Outlook.DocumentItem)Item; try { Outlook._MailItem myMailItem = (Outlook.MailItem)addinExplorer.Selection[1]; foreach (Outlook.Attachment oAttachment in myMailItem.Attachments) { if (oAttachment.FileName == oDocItem.Subject) { tempName = oAttachment.FileName; tempName = tempName.Substring(tempName.LastIndexOf(".")); oAttachment.SaveAsFile(UserLogManagerUtility.RootDirectory + @"\tempattachment" + tempName); //Read file data to bytes //byte[] fileBytes = File.ReadAllBytes(UserLogManagerUtility.RootDirectory + @"\tempattachment" + tempName); System.IO.FileStream Strm = new System.IO.FileStream(UserLogManagerUtility.RootDirectory + @"\tempattachment" + tempName, System.IO.FileMode.Open, System.IO.FileAccess.Read); System.IO.BinaryReader reader = new System.IO.BinaryReader(Strm); byte[] fileBytes = reader.ReadBytes(Convert.ToInt32(Strm.Length)); reader.Close(); Strm.Close(); //Replace any special characters are there in file name string fileName = Regex.Replace(oAttachment.FileName, strAttachmentReplacePattern, " "); //Add uplaod attachment item data to from list. UploadItemsData newUploadData = new UploadItemsData(); newUploadData.UploadType = TypeOfUploading.Attachment; newUploadData.AttachmentData = fileBytes; newUploadData.DisplayFolderName = activeDroppingFolder.Name; if (fileName.Contains(".")) { newUploadData.UploadFileName = fileName.Substring(0, fileName.LastIndexOf(".")); newUploadData.UploadFileExtension = fileName.Substring(fileName.LastIndexOf(".")); if (string.IsNullOrEmpty(newUploadData.UploadFileName.Trim())) { //check file name conatins empty add the date time newUploadData.UploadFileName = "Untitled_" + DateTime.Now.ToFileTime(); } } //Add to form frmUploadItemsListObject.UploadUsingDelegate(newUploadData); //Set dropped mail attachment items is uploaded. isDroppedItemUplaoded = true; newUploadData = null; //oDocItem.Delete(); break; } } } catch (InvalidCastException ex) { //Set dropped mail attachment items is uploaded to false isDroppedItemUplaoded = false; } if (isDroppedItemUplaoded == false) { tempName = oDocItem.Subject; tempName = tempName.Substring(tempName.LastIndexOf(".")); oDocItem.SaveAs(UserLogManagerUtility.RootDirectory + @"\tempattachment" + tempName, Type.Missing); System.IO.FileStream Strm = new System.IO.FileStream(UserLogManagerUtility.RootDirectory + @"\tempattachment" + tempName, System.IO.FileMode.Open, System.IO.FileAccess.Read); System.IO.BinaryReader reader = new System.IO.BinaryReader(Strm); byte[] fileBytes = reader.ReadBytes(Convert.ToInt32(Strm.Length)); reader.Close(); Strm.Close(); //Replace any special characters are there in file name string fileName = Regex.Replace(oDocItem.Subject, strAttachmentReplacePattern, " "); //Add uplaod attachment item data to from list. UploadItemsData newUploadData = new UploadItemsData(); newUploadData.UploadType = TypeOfUploading.Attachment; newUploadData.AttachmentData = fileBytes; newUploadData.DisplayFolderName = activeDroppingFolder.Name; if (fileName.Contains(".")) { newUploadData.UploadFileName = fileName.Substring(0, fileName.LastIndexOf(".")); newUploadData.UploadFileExtension = fileName.Substring(fileName.LastIndexOf(".")); if (string.IsNullOrEmpty(newUploadData.UploadFileName.Trim())) { //check file name conatins empty add the date time newUploadData.UploadFileName = "Untitled_" + DateTime.Now.ToFileTime(); } } //Add to form frmUploadItemsListObject.UploadUsingDelegate(newUploadData); newUploadData = null; //oDocItem.Delete(); } } } catch (Exception ex) { //throw ex; //////////////////////////////updated by Joy on 28.07.2012/////////////////////////////////// // EncodingAndDecoding.ShowMessageBox("FolderItem Add Event_DocItem Conv", ex.Message, MessageBoxIcon.Error); //////////////////////////////updated by Joy on 28.07.2012/////////////////////////////////// } try { XMLLogOptions userOptions = UserLogManagerUtility.GetUserConfigurationOptions(); for (int i = 0; i <= parentfolder.Items.Count; i++) { try { Outlook.MailItem me = (Outlook.MailItem)parentfolder.Items[i]; if (me.EntryID == mailitemEntryID) { ///////////////////////////modified by Joy on 10.08.2012//////////////////////////////////// if (isDroppedItemUplaoded == true) { me.Categories.Remove(0); me.Categories = newCatName; me.Save(); if (userOptions.AutoDeleteEmails == true) { UserMailDeleteOption(mailitemEntryID, parentfolder); } //parentfolder.Items.Remove(i); } ///////////////////////////modified by Joy on 10.08.2012//////////////////////////////////// } } catch (Exception) { } } } catch (Exception) { } if (!string.IsNullOrEmpty(mailitemEntryID)) { if (ItemType == TypeOfMailItem.ReportItem) { UserReportItemDeleteOption(mailitemEntryID, parentfolder); } else { ///////////////////////////Updated by Joy on 16.08.2012....to be updated later/////////////////////////////// // UserMailDeleteOption(mailitemEntryID, parentfolder); ///////////////////////////Updated by Joy on 16.08.2012....to be updated later/////////////////////////////// } } } } catch (Exception ex) { EncodingAndDecoding.ShowMessageBox("Folder Item Add Event", ex.Message, MessageBoxIcon.Error); } //AddToUploadList(Item); }
/// <summary> ///<c>ThisAddIn_Startup</c> Outlook startup event /// This Event is executed when outlook starts(outlook is opened) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ThisAddIn_Startup(object sender, System.EventArgs e) { try { //declare and initialize variables used for the Instant PLUS check Int32 result = 0; string filePath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\ITOPIA\\SharePoint Link 2010\\", "SharePoint Link.xml"); //Make the call to Instant PLUS and store the result result = Ip2LibManaged.CallInstantPLUS(Ip2LibManaged.FLAGS_NONE, "30820274020100300D06092A864886F70D01010105000482025E3082025A02010002818100BA81817A32C249909671428137ECFC2AEF45E5F746C218550C2191F525A15E65DCD87CAD8B46EB870E55897D1D185B9D88BCDDB6D44CB8B9DDFD7DB4948E8CF91743377F31DB733438828CA0EC3176D8650C8F4B77578E60285F55049D9A707C61FF75C7C626492415BBCBE8058E4F220826A356F1C50B29C92B354C61BEF21F0201110281800AF88F254E47A9F97242E5CB5DA4874DD1D6EF68E60B6AD7D389810E6BA0149C94853482ADD6FECBB58C8F9DF2A71472ADB0C1BF75E665381C1DF855EA9EF93BBA5432731B506EDFE944C217EB09F27AA8203C7D7310D78995A9549690836B313CDCD0B2FA6AD79576977EB44B33D46577E9EA6939DCF8388761E25C3FADF9B1024100F3F70346EEA01874427576DFF5136A9B3A1AB4522ADD2073669376540C6CE65A1A613D0F4754FAD4C8DA70D3F5F5F0D4DAF97B0CF49D9BDA0ECE0F8F46A19BBF024100C3B4DA9372E3FDE1787C322A5B74F21800CDD6A4A85C1DC9D18D40B0F8736BDD3CF45CD5DDB8FD626CD1F11B1127439036A4974D257AF38EBCDD1D9CE08FC1A1024100AC35E43211DA6B9D5C16AE43BC0DB4A9CEA9703A00239E6F93B36295AE6AFCF44EDB3A28E70ECF2CCA039AEFF8E9D72CD6CE38BDD9D8AA3F91FADDCE8C35D75902405095C369E40386A8228D7E1170F3EB370F63D0DA63713971382B1AA3392077B57373ADC1796A4A3796385438525B762C52BC3E4CF150BEA42FA6577CD4EFE65102405162E2024CE04279E92731B490BE2431758FA6D032B0DB85B2AC782956832095800B4A8AB7D6FC1DB905CA38508FC3CC49994A48940CF9BB5761C07A9289D492", filePath); if (11574 != result) { //this.Close(); //this.Application.ActiveExplorer().Close(); //this.Application.Quit(); return; } isAuthorized = true; #region Add-in Express Regions generated code - do not modify this.FormsManager = AddinExpress.OL.ADXOlFormsManager.CurrentInstance; this.FormsManager.OnInitialize += new AddinExpress.OL.ADXOlFormsManager.OnComponentInitialize_EventHandler(this.FormsManager_OnInitialize); //this.FormsManager.ADXBeforeFolderSwitchEx += // new AddinExpress.OL.ADXOlFormsManager.BeforeFolderSwitchEx_EventHandler(FormsManager_ADXBeforeFolderSwitchEx); this.FormsManager.Initialize(this); #endregion //DateTime dtExpiredDate = new DateTime(2010, 08, 05); //DateTime dtWorkingDate = DateTime.Now; //TimeSpan t = new TimeSpan(); //t = dtExpiredDate.Subtract(dtWorkingDate); //if (t.Days < 30 && t.Days >= 0) //{ //outlookObj = new Outlook.Application(); OutlookObj = Globals.ThisAddIn.Application; //Gte MAPI Name space outlookNameSpace = OutlookObj.GetNamespace("MAPI"); //Get inbox folder Outlook.MAPIFolder oInBox = outlookNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); //Get current user details to save the xml file based on user string userName = outlookNameSpace.DefaultStore.DisplayName; userName = userName.Replace("-", "_"); userName = userName.Replace(" ", ""); UserLogManagerUtility.UserXMLFileName = userName; //Get parent root folder Outlook.MAPIFolder olMailRootFolder = (Outlook.MAPIFolder)oInBox.Parent; //Get all folder oMailRootFolders = olMailRootFolder.Folders; //Create folder remove event oMailRootFolders.FolderRemove += new Microsoft.Office.Interop.Outlook.FoldersEvents_FolderRemoveEventHandler(oMailRootFolders_FolderRemove); //Set inbox folder as default try { OutlookObj.ActiveExplorer().CurrentFolder = oInBox; addinExplorer = this.Application.ActiveExplorer(); addinExplorer.BeforeItemPaste += new Microsoft.Office.Interop.Outlook.ExplorerEvents_10_BeforeItemPasteEventHandler(addinExplorer_BeforeItemPaste); //Create folder Switch event addinExplorer.FolderSwitch += new Microsoft.Office.Interop.Outlook.ExplorerEvents_10_FolderSwitchEventHandler(addinExplorer_FolderSwitch); //crete folder context menu disply this.Application.FolderContextMenuDisplay += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_FolderContextMenuDisplayEventHandler(Application_FolderContextMenuDisplay); this.Application.ContextMenuClose += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ContextMenuCloseEventHandler(Application_ContextMenuClose); strParentMenuTag = strParentMenuName; // Removing the Existing Menu Bar // RemoveItopiaMenuBarIfExists(strParentMenuTag); // Adding The Menu Bar Freshly // CreateParentMenu(strParentMenuTag, strParentMenuName); myTargetFolder = oInBox; CreateAddEventOnFolders(); //CreateDefaultAddEventOnFolders(); //Create outlook explorer wrapper class OutlookWindow = new OutlookExplorerWrapper(OutlookObj.ActiveExplorer()); OutlookWindow.Close += new EventHandler(OutlookWindow_Close); ((Outlook.ExplorerEvents_Event)addinExplorer).BeforeFolderSwitch += new Microsoft.Office.Interop.Outlook.ExplorerEvents_BeforeFolderSwitchEventHandler(ThisAddIn_BeforeFolderSwitch); oMailRootFolders.FolderChange += new Outlook.FoldersEvents_FolderChangeEventHandler(oMailRootFolders_FolderChange); foreach (Outlook.MAPIFolder item in oMailRootFolders) { try { item.Folders.FolderChange -= new Outlook.FoldersEvents_FolderChangeEventHandler(oMailRootFolders_FolderChange); } catch (Exception) { } item.Folders.FolderChange += new Outlook.FoldersEvents_FolderChangeEventHandler(oMailRootFolders_FolderChange); } Outlook.Items activeDroppingFolderItems; activeDroppingFolderItems = oInBox.Items; userOptions = UserLogManagerUtility.GetUserConfigurationOptions(); currentFolderSelected = oInBox.Name; currentFolderSelectedGuid = oInBox.EntryID; } catch (Exception ex) { ListWebClass.Log(ex.Message, true); } // } } catch (Exception ex) { EncodingAndDecoding.ShowMessageBox("StartUP", ex.Message, MessageBoxIcon.Error); } /// <summary> //code written by Joy ///initializes the object of timer /// </summary> System.Threading.AutoResetEvent reset = new System.Threading.AutoResetEvent(true); timer = new System.Threading.Timer(new System.Threading.TimerCallback(doBackgroundUploading), reset, 180000, 180000); GC.KeepAlive(timer); form = new Form(); form.Opacity = 0.01; form.Show(); form.Visible = false; }
/// <summary> /// ctor /// </summary> /// <exception cref="System.Runtime.InteropServices.COMException"/> public OutlookManager() { var current = System.Security.Principal.WindowsIdentity.GetCurrent(); m_impContext = current.Impersonate(); System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("OUTLOOK"); int collCount = processes.Length; if (collCount != 0) { #region comment //try //{ // // create an application instance of Outlook // oApp = new Microsoft.Office.Interop.Outlook.Application(); //} //catch (System.Exception ex) //{ // try // { // // get Outlook in another way // oApp = Marshal.GetActiveObject("Outlook.Application") as Microsoft.Office.Interop.Outlook.Application; // } // catch (System.Exception ex2) // { // // try some other way to get the object // oApp = Activator.CreateInstance(Type.GetTypeFromProgID("Outlook.Application")) as Microsoft.Office.Interop.Outlook.Application; // } //} #endregion try { // Outlook already running, hook into the Outlook instance m_outlookApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Outlook.Application") as Microsoft.Office.Interop.Outlook.Application; } catch (System.Runtime.InteropServices.COMException ex) { if (ex.ErrorCode == -2147221021) m_outlookApp = new Application(); else throw; } } else m_outlookApp = new Microsoft.Office.Interop.Outlook.Application(); m_outNameSpace = m_outlookApp.GetNamespace("MAPI"); m_allFolders = m_outNameSpace.Folders; m_outlookApp.NewMailEx += new ApplicationEvents_11_NewMailExEventHandler(outLookApp_NewMailEx); this.FoldersInOutlook = new List<string>(); m_inboxFolder = m_outNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox); m_FoldersToMonitor = new List<string>(); m_foldToMonitorInstances = new Dictionary<string, MAPIFolder>(StringComparer.OrdinalIgnoreCase); MAPIFolder mUserFolder = m_inboxFolder.Parent; if (mUserFolder != null) { foreach (object folder in mUserFolder.Folders) { MAPIFolder mapiFolder = folder as MAPIFolder; if (mapiFolder != null) { this.FoldersInOutlook.Add(mapiFolder.Name); } } } }