Preeti
Preeti

Reputation: 1386

How to Create Site using Sharepoint web services?

I am tring to create site on sharepoint programatically using Sharepoint Web Services.(C#).

I tried Admin.asmx service (CreateSite method).

But it's showing error:

"An unhandled exception of type 'System.InvalidOperationException' occurred in System.Web.Services.dll".

I tried with all possible parameters. Curremtly referring Below Links:

  1. http://www.oliebol.org/blog/Lists/Posts/Post.aspx?ID=6
  2. http://msdn.microsoft.com/en-us/library/administration.admin.createsite.aspx

My Code:

Admin admService             = new Admin();
admService.Credentials       = new NetworkCredential(username,password,domain);
admService.Url               = "http://mychserver/_vti_adm/admin.asmx";
admService.PreAuthenticate   = true;
try
{
  String SitePath   = "http://myserver/SiteDirectory/SharepointSampleSite";
  admService.CreateSite(SitePath,"First Site", "Sample Site", 1033, "STS#0",
                       "Domain\\username",username,userid, "", "");
}
catch (System.Web.Services.Protocols.SoapException ex)
{
 MessageBox.Show("Message:\n" + ex.Message + "\nDetail:\n" +ex.Detail.InnerText +
                 "\nStackTrace:\n" + ex.StackTrace);
}

Thanx,

Upvotes: 1

Views: 4934

Answers (3)

chixcancode
chixcancode

Reputation: 29

I was getting this as well, I think that it is related to the userid value. Make sure that it is an email associated with the domain user you are using. If the domain user does not have an email, leave the parameter blank.

Upvotes: 1

Chloraphil
Chloraphil

Reputation: 2849

Try changing STS#0 to STS#1. STS#1 is a blank site. If that works then you know the problem is with the site template.

Check the values for the parameters "OwnerLogin", "OwnerName", and "OwnerEmail". Mine are of the format: domain\\username, username, username@domain. Perhaps the email address is invalid (you are passing "userid" which I assume is not a valid email address?)

Upvotes: 1

Marc
Marc

Reputation: 1178

  • Is the account calling the service part of the Farm Admin group?
  • Using STS#0 as a param, thats a "Team Site". Are the relevant features deployed/activated for the that Site Collection?
  • Are you able to call other web service methods successfully?

    Upvotes: 1

  • Related Questions