Tuesday, June 5, 2012

How to enable Sync to SharePoint Workspace for SharePoint document libraries

Enable Sync to SharePoint Workspace using SharePoint Object Model:



  1. Open Visual Studio 2010.
  2. Go to File => New => Project.
  3. Select Console Application template from the installed templates.
  4. Enter the Name and Click on Ok.
  5. Add the following Reference.

    Microsoft.SharePoint.dll
  6. Add the following Namespace.

    Using Microsoft.SharePoint;
 static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://demoshare:6969/sites/"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists.TryGetList("History");
                    if (list != null)
                    {
                        //Enable Sync to SharePoint Workspace
                        list.ExcludeFromOfflineClient = false;
                        //To Disable Sync to SharePoint Workspace => list.ExcludeFromOfflineClient = true;
                        list.Update();
                        Console.WriteLine("Sync to SharePoint Workspace is Enabled");
                    }
                    else
                    {
                        Console.WriteLine(list.Title + " does not exists in the site");
                    }
                    Console.ReadLine();
                }
            }
        }
  1. Build the solution.
  2. Hit F5.
enabled sync to workspace button.

No comments:

Post a Comment