SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to create a SharePoint web application (on SharePoint2007) in C#. How differently I tried, it ends up with the same access denied error in the Provisioning step. The error message does not contain much details. It only says COM Error : Access Denied. Below is my code.

      SPWebApplicationBuilder webAppBuilder = new SPWebApplicationBuilder(SPFarm.Local);
      webAppBuilder.ServerComment = "App1";
      webAppBuilder.Port = 81;
      webAppBuilder.RootDirectory = new DirectoryInfo(@"C:\Inetpub\wwwroot\wss\VirtualDirectories\81");
      webAppBuilder.UseNTLMExclusively = true;
      webAppBuilder.AllowAnonymousAccess = false;
      webAppBuilder.UseSecureSocketsLayer = false;
      webAppBuilder.ApplicationPoolId = "SharePoint - 81";
      webAppBuilder.IdentityType = IdentityType.NetworkService;

      webAppBuilder.CreateNewDatabase = true;    
      webAppBuilder.DatabaseServer = "abcdef"; //Database server   
      webAppBuilder.DatabaseName = "WebApp81";  // Database name

      SPWebApplication newApplication = webAppBuilder.Create();
      newApplication.Provision(); //Provision it into web farm 

The last line is the one that gives the error. Access Denied.

I'm using a domain account. When I investigated a little bit more I saw,

  • The database and the set of tables are created.
  • At SharePoint admin page web application lists, the application is listed.
  • But I can't create a site collection in it (Since Provisioning has not properly been completed)

Have someone got any idea of what I am missing here?

Thanks a lot...

share|improve this question

migrated from Jun 22 '12 at 10:19

This question came from our site for professional and enthusiast programmers.

Try to execute this code with a domain account who has privilege on your SharePoint Farm.

In which context do you run this code ? via an event receiver ? feature activation ?

share|improve this answer
Hi Le_Ferdo, I already have privileges on my SharePoint Farm as I have created it with the same user account i'm using to execute this program. Is there any other way to confirm that? And I'm using this code for some test automations, where I create a web application and some sites in SharePoint. – stux Jun 29 '12 at 2:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.