Using SharePoint API

The SharePoint API offers a great way to modifiy and create SharePoint content. You only need to be aware of the following restrictions:

  1. You need to run the code on the front-end server on which you want to use the API on. Otherwise use the SharePoint web services.
  2. The user executing the code must be be farm administrator.
  3. The user executing the code must have the following permissions on the database:
    1. Configuration database: Pulic, wss_content_application_pools
    2. Content database: db_owner
    3. Admin content database: Public

If this can be done there is nothing in the way using the SharePoint API. Remember to use the Dispose pattern for the SPSite and SPWeb objects.

To access a site you may use this code:

try {
   SPFarm.local;
   SPSite site = new SPSite("url");
   SPWeb web = site.OpenWeb();
}
finally {
   site.Dispose();
   web.Dispose();
}

Note: Never, ever dispose the SPContext.Current.Web.

Leave a Reply

Your email address will not be published. Required fields are marked *