El Blanco's Office 2007 Blog

Thursday, September 07, 2006

Weird Exception when Creating a Web Programatically

Sorry I haven't posted for a long time, but I've been mega-busy working on various SharePoint goodies and haven't found the time . . .

My latest problem I'm seeing revolves around programatically creating a web i.e. creating a sub-site. I need to create a custom web service, and one of the methods on that web service must create a site - easy you'd think. I used the following code:

analysisSite = new SPSite(DealSiteHelper.AnalysisWebURL);
analysisWeb = analysisSite.OpenWeb();
analysisWeb.AllowUnsafeUpdates = true;
SPWeb newWeb = analysisWeb.Webs.Add(webUrl, title, title, 1033, "STS", true, false);
analysisWeb.AllowUnsafeUpdates = false;


However when the code hit the line where we are adding the new web to the Webs collection I get a Null Reference Exception with the following stack trace:

at Microsoft.SharePoint.SPSite.get_Features()
at Microsoft.SharePoint.SPElementProvider.QueryForWorkflowDefinitions(SPWeb web)
at Microsoft.SharePoint.Workflow.SPWorkflowManager. RegisterFeatureTemplates(SPWorkflowTemplateCollection wftemplates, SPWeb web)
at Microsoft.SharePoint.SPWeb.get_WorkflowTemplates()
at Microsoft.SharePoint.Workflow.SPWorkflowAssociation. get_BaseTemplate()
at Microsoft.SharePoint.Workflow.SPWorkflowAssociation. get_BaseTemplateInternal()
at Microsoft.SharePoint.Workflow.SPWorkflowAssociation.SetTaskList(SPList list)
at Microsoft.SharePoint.Workflow.SPWorkflowAssociationCollection. SetUtilityLists(SPWorkflowAssociation wa, Boolean forceUtilityListCreation)
at Microsoft.SharePoint.Workflow.SPWorkflowAssociationCollection. AddCore(SPWorkflowAssociation wa, Guid id, SPList list, Boolean forceUtilityListCreation)
at Microsoft.SharePoint.Workflow. SPContentTypeWorkflowAssociationCollection. AddCoreCT(SPWorkflowAssociation associationTemplate)
at Microsoft.SharePoint.Workflow. SPContentTypeWorkflowAssociationCollection. UpdateOrAdd(SPWorkflowAssociation associationTemplate)
at Microsoft.SharePoint.SPContentType.CopyWorkflowAssociationsTo(SPContentType ctDst)
at Microsoft.SharePoint.SPWeb.SyncNewLists()
at Microsoft.SharePoint.SPWeb.ApplyWebTemplate(String strWebTemplate)
at Microsoft.SharePoint.SPWeb.CreateWeb(String strWebUrl, String strTitle, String strDescription, UInt32 nLCID, String strWebTemplate, Boolean bCreateUniqueSubweb, Boolean bConvertIfThere)
at Microsoft.SharePoint.SPWeb.SPWebCollectionProvider.CreateWeb(String strWebUrl, String strTitle, String strDescription, UInt32 nLCID, String strWebTemplate, Boolean bCreateUniqueSubweb, Boolean bConvertIfThere)
at Microsoft.SharePoint.SPWebCollection.Add(String strWebUrl, String strTitle, String strDescription, UInt32 nLCID, String strWebTemplate, Boolean useUniquePermissions, Boolean bConvertIfThere)
at Company.SharePoint.AnalysisExecution.DealSiteWebService.CreateDealSite(String title) in D:\\My Documents\\Visual Studio 2005 Projects\\DealSiteWebService\\DealSiteWebService.asmx.cs:line 40

If I extract the above code and place it in a normal Windows Console Application, then everything works OK - this exception only occurs when I call this code in a web service method.

I've come accross the same problem mentioned on Todd Baginski's blog, but I don't think he's found a solution yet either.

If I ever manage to work out what this problem is I shall post again, but in the mean time lets hope that it's fixed in TR :)

1 Comments:

  • [b][url=http://cheap-car-insurance.quickfreehost.com] admiral car insurance [/url][/b]
    [b][url=http://seoguide.ws] allstate car insurance [/url][/b]
    [b][url=http://nutritionguide.ws] car insurance [/url][/b]
    [b][url=http://affiliaterevenueguide.ws] teen car insurance [/url][/b]
    [b][url=http://careeremploymentguide.com] car accident insurance [/url][/b]
    [b][url=http://fitnessequipmentguide.net] cheap car insurance rate [/url][/b]
    [b][url=http://inetmarketingguide.ws] cheap car insurance quote uk [/url][/b]
    [b][url=http://interiordecorguide.ws] car insurance price [/url][/b]
    [b][url=http://landscapingguide.ws] online car insurance [/url][/b]
    [b][url=http://mortgageguide.ws] admiral car insurance [/url][/b]
    [b][url=http://personalfinanceguide.ws] geico car insurance quote [/url][/b]
    [b][url=http://trafficbuildingguide.net] nj car insurance [/url][/b]
    [b][url=http://vacationrentalsguide.ws] car insurance policy [/url][/b]
    [b][url=http://wealthbuildingguide.net] car
    insurance philadelphia [/url][/b]
    [b][url=http://progressive-car-insurance.wealthbuildingguide.net] car insurance rating [/url][/b]
    [b][url=http://compare-car-insurance.vacationrentalsguide.ws] car insurance quote uk [/url][/b]
    [b][url=http://cheapest-car-insurance.trafficbuildingguide.net] compare car insurance [/url][/b]
    [b][url=http://classic-car-insurance.personalfinanceguide.ws] car insurance coverage [/url][/b]
    [b][url=http://free-car-insurance-quote.mortgageguide.ws] texas car insurance [/url][/b]
    [b][url=http://cheap-car-insurance-quote.landscapingguide.ws] aa car insurance [/url][/b]
    [b][url=http://low-cost-car-insurance.interiordecorguide.ws] usaa car insurance [/url][/b]
    [b][url=http://car-insurance-quote.inetmarketingguide.ws] online car insurance rate [/url][/b]
    [b][url=http://car-insurance-rates.homeimprovementguide.ws] teen car insurance [/url][/b]
    [b][url=http://new-york-insurance.fitnessequipmentguide.net] teen car insurance [/url][/b]
    [b][url=http://california-car-insurance.estateguide.ws] agent car company home insurance life quote rate [/url][/b]
    [b][url=http://car-insurance-rate.careeremploymentguide.com] car insurance canada [/url][/b]
    [b][url=http://auto-insurance-company.affiliaterevenueguide.ws] agent car company home insurance life quote rate [/url][/b]
    [b][url=http://online-car-insurance.acneguide.ws] aig car insurance [/url][/b]
    [b][url=http://auto-cheap-insurance.nutritionguide.ws] car insurance quote online uk [/url][/b]
    [b][url=http://auto-insurance-quote.seoguide.ws] antique car insurance [/url][/b]

    http://cheap-car-insurance.quickfreehost.com

    Random Keyword: :)
    [b]auto cheap insurance[/b]

    By Anonymous Anonymous, at 11:48 am  

Post a Comment

<< Home