Alexander Anikin's blog

My personal blog

Connect SharePoint to Outlook

leave a comment »

Sometimes it’s good to add SharePoint connection to Outlook from code.

This function can do this using Outlook Interop and MAPI namespace:

using Microsoft.Office.Interop.Outlook;

static void AddSpsFolder(string name, string syncurl)
        {
            Microsoft.Office.Interop.Outlook._Application oApp = new Microsoft.Office.Interop.Outlook.Application();
            _NameSpace oNS = (_NameSpace)oApp.GetNamespace(“MAPI”);
            oNS.Logon(Type.Missing, Type.Missing, true, true);

            bool useDefaultTTL = true;

            Folder oFolder =   oNS.OpenSharedFolder(syncurl, name, Type.Missing, useDefaultTTL)  as Folder;
            Explorer oExp = oApp.Explorers.Add(oFolder, OlFolderDisplayMode.olFolderDisplayNormal);
            oExp.Display();

            oNS.Logoff();

            oApp = null;
          
            oNS = null;
            oFolder = null;
            oExp = null;
        }

Where:

  •  name – folder storage  name;
  • syncurl – stssync path (like stssync://sts/?ver=1.1&type=tasks&cmd=add-folder&base-url=https%3A%2F%2Ftest%2Esp%2Edomain%2Enet&list-url=%2FLists%2FTasks%2F&guid=%7B1a2a4e01%2D25af%2D4cca%2D9175%2D5511d5986d45%7D&site-name=A&list-name=Tasks)

PS: You can use it in console an “runas /profile /env /user …” as different user.

Advertisements

Written by Alex Anikin

February 28, 2011 at 1:48 pm

Posted in Office, Sharepoint

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: