1

我正在使用 C# 开发 Outlook 插件。野兔我提取所有附件(在 doc 或 docx 中),这些附件与选定的邮件一起附加。我已经使用插件在工具栏上创建了一个按钮。当我单击按钮时,所有带有所选邮件的附件都会进入我的数据库。现在我的问题是,当我单击按钮时,在处理期间会发生一些处理想要在我的 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);
        }
    }
4

0 回答 0