Alexander Anikin's blog

My personal blog

Archive for the ‘Office’ Category

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);


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


  •  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.

Written by Alex Anikin

February 28, 2011 at 1:48 pm

Posted in Office, Sharepoint