在Outlook Addins中显示进度栏

时间:2013-05-23 10:00:53

标签: c# outlook-addin outlook-2007

我正在使用C#开发Outlook Add ins。我提取所有附件(在doc或docx中)附加所选邮件的附件。我在工具栏上创建了一个按钮,使用add in.when我点击按钮然后所有附件与所选邮件进入我的数据库。现在我的问题是,当我点击按钮时,一些处理发生在处理时间我我希望在我的Outlook窗口中显示一个进度条,直到它完成提取。任何人都可以帮我解决这个问题。这里我还包含提取邮件附件的代码并发送到数据库

private void ThisApplication_NewMail()
    {
        DataTable dtImportedData = new DataTable();
        Outlook.Explorer currExplorer = this.Application.ActiveExplorer();
        Outlook.MAPIFolder folder = this.Application.ActiveExplorer().CurrentFolder;
        Outlook.Items inBoxItems = folder.Items;
        Outlook.MailItem item = null;
        const string destinationDirectory = @"C:\TestFileSave";
        if (!Directory.Exists(destinationDirectory))
        {
            Directory.CreateDirectory(destinationDirectory);
        }
        dtImportedData.Columns.Add("Select", typeof(bool));
        dtImportedData.Columns.Add("Name");
        dtImportedData.Columns.Add("Experience");
        dtImportedData.Columns.Add("Company Name");
        dtImportedData.Columns.Add("Email");
        dtImportedData.Columns.Add("Mobile");
        dtImportedData.Columns.Add("Date Of Birth");
        dtImportedData.Columns.Add("Designation");
        dtImportedData.Columns.Add("Location");
        dtImportedData.Columns.Add("Qualification");
        dtImportedData.Columns.Add("Skill Set");
        dtImportedData.Columns.Add("Path");

        //DataRow dr = null;
        DataRow drExtract = null;
        try
        {
            string strFileName = string.Empty;
            Outlook.Selection selections = currExplorer.Selection;
            for (int i = 1; i <= selections.Count; ++i)
            {
                object newEmail = (object)selections[i];
                if (newEmail != null && (newEmail is Outlook.MailItem))
                {
                    item = (Outlook.MailItem)newEmail;
                    if (item.Attachments.Count > 0)
                    {
                        for (int j = 1; j <= item.Attachments.Count; j++)
                        {
                            if (item.Attachments[j].FileName.Contains(".doc") || item.Attachments[j].FileName.Contains(".docx") || item.Attachments[j].FileName.Contains(".rtf"))
                            {
                                string filePath = Path.Combine(destinationDirectory, item.Attachments[j].FileName.ToString());                                    
                                item.Attachments[j].SaveAsFile(filePath);

                                string m_Content = ClsWordManager.ReadWordFile(filePath);                                   
                                drExtract = dtImportedData.NewRow();
                                ClsResumeExtractor objExtractResume = new ClsResumeExtractor();
                                drExtract["Select"] = true;
                                drExtract["Name"] = objExtractResume.ExtractName(m_Content);
                                drExtract["Email"] = objExtractResume.ExtractEmailAddressesFromString(m_Content);
                                drExtract["Mobile"] = objExtractResume.ExtractMobile(m_Content);
                                drExtract["Qualification"] = objExtractResume.ExtractQualification(m_Content);                                  
                                drExtract["Designation"] = objExtractResume.ExtractDesignation(m_Content);
                                drExtract["Company Name"] = objExtractResume.ExtractCompanyName(m_Content);
                                drExtract["Location"] = objExtractResume.ExtractCurrentLocation(m_Content);
                                drExtract["Date Of Birth"] = objExtractResume.ExtractDateOfBirth(m_Content);
                                drExtract["Experience"] = objExtractResume.ExtractYearOfExperience(m_Content);
                                drExtract["Skill Set"] = objExtractResume.ExtractSkillSet(m_Content);
                                drExtract["Path"] = filePath;
                                dtImportedData.Rows.Add(drExtract);
                            }
                        }
                    }
                    else
                    {
                        System.Windows.Forms.MessageBox.Show("Select Email which have Attchments..!");
                    }                  
                }                 
            }
            if (dtImportedData.Rows.Count > 0)
            {
                SaveImportedDataOutlook objSaveImportedDataOutlook = new SaveImportedDataOutlook();
                objSaveImportedDataOutlook.grdCandidate.DataSource = dtImportedData;
                ClsCommons.OpenDialog(objSaveImportedDataOutlook);
            }
        }
        catch (Exception ex)
        {
            string errorInfo = (string)ex.Message.Substring(0, 11);
        }
    }

0 个答案:

没有答案