0
votes

I have a following requirement

Requirement : "Create Site collection programatically on a web application which is hosted on a remote server and then create Sub site in it"

I am able to successfully create Site collection using Admin.asmx web service. But, for Sub sit when i use following code - it throws an exception "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"

Uri site = new Uri("http://SharePoint2010Site/"); 
string webServicePath = "_vti_bin/Sites.asmx";
string webServiceUrl = Path.Combine(site.AbsoluteUri, webServicePath);

Sites webService = new Sites();
webService.Credentials = CredentialCache.DefaultNetworkCredentials;
webService.Url = webServiceUrl;

//the following line creates the sub site
string result = webService.CreateWeb("Sub Site", "Sub Site", "Sub Site Desc", "STS#0", 
    1033, true, 1033, true, 1033, true, true, true, true, true, true, true);

What can be the reason for Access denied exception?

2

2 Answers

0
votes

Are you sure you made yourself the owner of the site collection.

What parameters did you pass to the site collection create?

0
votes

As you mentioned you want to access remote site, try passing UserName, Password and Domain name as shown below.

webService.Credentials = new System.Net.NetworkCredential("UserName Here", "Password Here", "Domain Name Here");