0

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...

1 Answer 1

1

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 ?

1
  • 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
    Commented Jun 29, 2012 at 2:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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