Outlook plug-in: link address for exporting rss, rsslink

Source: Internet
Author: User

Outlook plug-in: link address for exporting rss, rsslink

Because you are not familiar with rss applications, use Outlook to receive rss. There is no difference in the use process and in-time email reception.

The only pity is that outlook does not download all webpages for security reasons, so you need to open a browser every time. Sometimes you need to read more or add it to Favorites (for example, I am going to join the pocket) through a browser. When there are too many web pages, I feel a little annoying.

If necessary, find a solution.

My solution: Create an outlook plug-in to save the required URL.

IDE: vs2010.

Outlook: 2007

Step 1: Create a project named RssLinkExport. Note that the outlook plug-in type under the c # node is not selected. Use a General Plug-in model to better control outlook.

 

 

Step 8: write the code. Since there are not many codes, they are all written in the Connect class.

Declarative Variables

Private string rssEntryID; // used to identify the rss directory. developed according to outlook, each object has an id. Private Microsoft. Office. Interop. Outlook. Application app; // cache the outlook object CommandBarButton exportBtn; // control Regex reUrl; // regularizedobject to filter URLs.

Initialization

public Connect(){     

rssEntryID = null;    
// Initialize the regular expression. For the reason for writing this, refer to the rss data format.
     reUrl = new Regex("HREF=\"(?<key>http:[^\"]+)\"", RegexOptions.Compiled);}
Cache application Object
public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom){
    applicationObject = application;
AddInInstance = addInInst;

// Cache the application object at the startup stage. If you are familiar with com development, you should be familiar with this.
    app = application as Microsoft.Office.Interop.Outlook.Application;
}
 
Add the toolbar button to trigger the save operation when necessary.
public void OnStartupComplete(ref System.Array custom){
    // save rss   ID
     Microsoft.Office.Interop.Outlook.MAPIFolder rssFolder = app.ActiveExplorer().Session.GetDefaultFolder(OlDefaultFolders.olFolderRssFeeds); 
     rssEntryID = rssFolder.EntryID;
CommandBars commandBars = app. ActiveExplorer (). CommandBars;

// Judgment: in case of a plug-in exception, if the newly added control is not removed, it is not required to be added.
     foreach (CommandBarControl control in commandBars["Standard"].Controls)
     {     
         if (control.Caption == "export")
         {                         
               exportBtn = control as CommandBarButton;  
               break;
         }
    }
    if (exportBtn == null)
    {
         exportBtn = (CommandBarButton)commandBars["Standard"].Controls.Add(1

, System.Reflection.Missing.Value

, System.Reflection.Missing.Value

, System.Reflection.Missing.Value

, System.Reflection.Missing.Value);
         exportBtn.Caption = "export";    
    }
    exportBtn.Click += new _CommandBarButtonEvents_ClickEventHandler(exportBtn_Click);}
 
Remove control
public void OnBeginShutdown(ref System.Array custom)  
{

// Destroy the new control before exiting the program.
     if (exportBtn != null)             
     {
             exportBtn.Delete(System.Reflection.Missing.Value);
             exportBtn = null;             
     }
}
Trigger event
 void exportBtn_Click(CommandBarButton Ctrl, ref bool CancelDefault)         
{
 
     List<string> urls = new List<string>();
// Check whether the current directory is rss
     Microsoft.Office.Interop.Outlook.MAPIFolder selectedFolder = app.ActiveExplorer().CurrentFolder;                 
     Microsoft.Office.Interop.Outlook.MAPIFolder parentFolder = selectedFolder.Parent as Microsoft.Office.Interop.Outlook.MAPIFolder;                 
     if (parentFolder == null) return;                                               
     if (rssEntryID == null || rssEntryID.Equals(parentFolder.EntryID) == false) return;                 
// Obtain the list of objects selected after the interface operation. Selection is an office object.
     Selection selectdItems = app.ActiveExplorer().Selection;                 
     if (selectdItems == null) return;                 
     foreach (object objSelected in selectdItems)                 
     {                     
// Convert to PostItem
           Microsoft.Office.Interop.Outlook.PostItem pItem = objSelected as Microsoft.Office.Interop.Outlook.PostItem;                     
           if (pItem == null) continue;                     
// Obtain the format. This is a defensive encoding because all the rss objects I commonly use are html.
           OlBodyFormat bodyFmt = pItem.BodyFormat;                     
           string pItemBody = null;                     
           if (bodyFmt == OlBodyFormat.olFormatHTML)                     
           {                         
             pItemBody = pItem.HTMLBody;                     
           }                     
           else                     
           {                         
             pItemBody = pItem.Body;                     
           }                     
// The exported object is marked with blue classification, which is not deleted yet. Therefore, if it has been marked, it indicates that it has been exported.
           if (pItem.Categories == null)                     
           {                         
              pItem.Categories = "Blue Category";                         
// This step is critical. Otherwise, outlook does not immediately refresh the interface.
              pItem.Save();                         
// Obtain the url
              Match urlMa = reUrl.Match(pItemBody);                         
              if (urlMa.Success)                         
              {                             
                urls.Add(urlMa.Groups["key"].ToString());                         
              }                     
           }                 
     }                 
// Save all URLs to my folder.
     if (urls.Count > 0)                 
     {                     
        string baseFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);                     
        string targetFolder = string.Format("{0}\\bel", baseFolder);                     
        DirectoryInfo di = new DirectoryInfo(targetFolder);                     
        if (di.Exists == false)                     
        {                         
           di.Create();                     
        }                     
        DateTime dtNow = DateTime.Now;                     
        string targetFile = string.Format("{0}\\urls_{1}{2}{3}.txt", targetFolder, dtNow.Year, dtNow.Month, dtNow.Day);                     
        StreamWriter sw = new StreamWriter(targetFile, true);                     
        foreach (string url in urls)                     
        {                         
          sw.WriteLine(url);                     
        }                     
        sw.Close();       
// You should see the url text at this time.
     }

}


Step 9: Debug. The default external program is vs2010, so you need to point to the outlook directory.

 

Step 10: After the plug-in is loaded successfully, the control displayed on the interface is "export ".

 

Step 11: After you click export, the selected item displays the blue category.

 

Step 12: vs2010 will automatically create a release package, but it will not be built by default. You need to build it manually.

 

Step 13: This is a successfully created installer.

 

Step 14: Try it.

 

Finally, I would like to thank Dr. Shi for his regular expression technical support.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.