Working with SharePoint from External ASP.NET Web Apps.

SharePoint is essential an extention of ASP.NET and so with a just a little development work a SharePoint site can be extended in almost any way such as building custom Web Parts or accessing SharePoint from other ASP.NET web applications.

Before extending SharePoint we will first need a solid understanding of the Microsoft.SharePoint namespace. There are two core objects in this namespace:

  • SPSite : Represents a SharePoint site collection which is
    likely to be a top level site and all its sub-sites
  • SPWeb : Represents a specific site within the collection.

Before working with external SharePoint sites in an ASP.NET web app you will
first need to add a reference to the Microsoft.SharePoint.dll
library (this is available at C:Program FilesCommon FilesMicrosoft Sharedweb server
extensions12ISAPI
)

Working with SPSite

To reference a SharePoint site from an external app (normally an ASP.NET web app) you will first need to create an SPSite object and pass in either the absolute URL or the GUID of the site collection. The URL may  be a SharePoint Portal Server site, a Windows SharePoint Services site collection or a Windows SharePoint Services site. The below example shows the creation of an SPSite object by passing the URL.

    SPSite sitecollectionObj = new SPSite("http://spsite");

    Console.WriteLine(sitecollectionObj.ContentDatabase.ToString( ));

    SPSite.Dispose( ); 

   Console.ReadLine( );

Note that the new keyword is used in the above example and you will be required to call Dispose. An alternative is to use the using contruct which avoids the requirement to call Dispose

    using (SPSite sitecollectionObj = new SPSite("http://spsite");)

    {

    Console.WriteLine(sitecollectionObj.ContentDatabase.ToString( ))

    }

Working with SPWeb

Most developers will be interested in working with a specific SharePoint site. Once the SPSite object has been created you can proceed to get a reference to the SPWeb object:

    SPWeb siteObj = sitecollectionObj.AllWebs[spSiteName];

Continues…

Pages: 1 2




Array

No comments yet... Be the first to leave a reply!