SharePoint sites creation using C# through WebServices

Posted by Shantha Kumar on 1st July 2007

I am a new to SharePoint webservices and now working on customizing webservices for sharepoint. Here is a sample code for creating a site in SharePoint using it’s webservices.

Creating Site:

To create a site, project requires a methods to access sites for creating and deleting. Those methods and properties are available in admin webservice.

http://server-name:port/_vti_adm/admin.asmx

is a admin webservice available in directory called Root:Program FilesCommon FilesMicrosoft Sharedweb server extensions12ADMISAPIadmin.asmx

Add this reference to the project, and change the reference name to SPAdminService.
The following code helps to create a site for the particular URL.

 protected void createSite()
{
string siteURL=”http://servername:port/site”;   \Site URL
string siteTitle=”TestSite”;                  \Site Title
string sitedes=”Site for testing”;            \Site Description
int lcid=1033;                                     \Local identifier – 1033 for English(US)
string siteTemp=”STS#0″;     \Site Template “STS#0″-Team Site, “STS#1″-Blank

SiteSPAdminService.Admin adminService=new SPAdminService.Admin();
\Authentication for default users crenntly logged in OS
adminService.Credentials = CredentialCache.DefaultCredentials;

\Assigning authentication by code.  
adminService.Credentials=new NetworkCredential(”UserName”,”Password”,”Domain”);
try
{
adminService.CreateSite(siteURL, siteTitle , sitedes , lcid, siteTemp, “domain\UserName”, “Display_UserName”, “email”, “”, “”);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}

    14 Comments »

  1. Good luck, we will keep in touch with as you/we move forward.

    Comment by Ari — July 1, 2007 @ 3:43 pm

  2. yenna shantha , lull after the first post :-) , welcome to blogging

    Comment by rtshiva — August 10, 2007 @ 9:40 am

  3. good approach….

    Comment by kiran reddy — August 22, 2007 @ 3:36 pm

  4. myspace code [url=http://color.iega.info/sm.html#967376258]myspace code[/url] http://color.iega.info/sm.html 428420431

    Comment by comment generator hiding myspace — October 6, 2007 @ 8:47 pm

  5. Hi!
    I wrote a same code, but it always said this:

    System.Web.Services.Protocols.SoapException: Exception of type ‘Microsoft.SharePoint.SoapServer.SoapServerException’ was thrown.
    :(
    Any idea?

    Comment by Zelota — October 8, 2007 @ 2:25 pm

  6. hey i was getting the same error..!
    ‘Microsoft.SharePoint.SoapServer.SoapServerException’
    more over this error is coming only for thisweb services..!

    Comment by ramesh — October 24, 2008 @ 9:21 pm

  7. I also get the soapServerException. No clue yet how to fix it! Has anyone fixed that?

    Comment by Bart — October 30, 2008 @ 8:54 pm

  8. I would like to know what type of app you all trying to do i.e.,(webpart, windows application or web app,), and want to know about your code about webservice calling..
    Any way, If you get this soapServerException please refer the below link, http://support.microsoft.com/kb/830342

    Comment by Shantha Kumar — November 22, 2008 @ 10:06 pm

  9. Has anyone got this approach on creating sitecollections working with custom site-templates? I’ve been struggling with this quite a few hours :-( ……

    Comment by Harry Solsem — December 24, 2008 @ 2:46 am

  10. This url suppose to be

    http://server-name:port/_vti_adm/admin.asmx

    instead of bin (adm)

    Comment by Aamir Bashir — March 9, 2009 @ 3:40 pm

  11. uable to access admin.asmx, it is been blocked.
    i did some google and asmx removed from blocked files, then msg prompt file not found. please direct me in right path.
    Thanks

    Comment by Janardhan — April 8, 2009 @ 12:47 pm

  12. I want to create site using custom template i.e stp file.

    How can i acheive using createsite webservice?

    Comment by shobha — May 4, 2009 @ 2:34 pm

  1. myspace login
  2. Mesothelioma Cases

RSS feed for comments on this post. TrackBack URL

Leave a comment