SharePoint Online, SPWebCollection.Add method (String, String, String, UInt32, SPWebTemplate, Boolean, Boolean)

I have created a Sandbox-solution With a List Event Receiver. When a New item is added to the list, a Workspace should be created based on a sitetemplate.  

 

Code in my latest attemp;

 wWeb.AllowUnsafeUpdates = true;
 newWeb =   wWeb.Webs.Add(properties.ListItem[numb].ToString(), properties.ListItem[numb].ToString() + " " + properties.ListItem["Title"].ToString(), "", 1044, arbeidsrommal, false, false);
 wWeb.Update();
wWeb.AllowUnsafeUpdates = false;

 

this work for 4 list items, sites wore created. But 1h later when i tried it casted a error for all items i created:

 

Microsoft.SharePoint.SPException: The Web site "/project/space/7823-15152" is already in use. ---> System.Runtime.InteropServices.COMException: <nativehr>0x800700b7</nativehr><nativestack></nativestack>The Web site "/project/space/7823-15152" is already in use..
   at Microsoft.SharePoint.Library.SPRequestInternalClass.CreateWeb(String bstrUrl, String bstrTitle, String bstrDescription, UInt32 nLCID, Boolean bCreateUniqueWeb, Guid& pguidAppInstanceId, String bstrAppWebDomainId, Boolean bConvertIfThere, Guid& pgWebId, Guid& pgRootFolderId, Boolean bCreateSystemCatalogs)
   at Microsoft.SharePoint.Library.SPRequest.CreateWeb(String bstrUrl, String bstrTitle, String bstrDescription, UInt32 nLCID, Boolean bCreateUniqueWeb, Guid& pguidAppInstanceId, String bstrAppWebDomainId, Boolean bConvertIfThere, Guid& pgWebId, Guid& pgRootFolderId, Boolean bCreateSystemCatalogs)
   --- End of inner exception stack trace ---

Server stack trace: 
   at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx)
   at Microsoft.SharePoint.Library.SPRequest.CreateWeb(String bstrUrl, String bstrTitle, String bstrDescription, UInt32 nLCID, Boolean bCreateUniqueWeb, Guid& pguidAppInstanceId, String bstrAppWebDomainId, Boolean bConvertIfThere, Guid& pgWebId, Guid& pgRootFolderId, Boolean bCreateSystemCatalogs)
   at Microsoft.SharePoint.SPWeb.CreateWeb(String strWebUrl, String strTitle, String strDescription, UInt32 nLCID, String strWebTemplate, Boolean bCreateUniqueSubweb, Boolean bConvertIfThere, Guid appInstanceId)
   at Microsoft.SharePoint.SPWeb.SPWebCollectionProvider.CreateWeb(String strWebUrl, String strTitle, String strDescription, UInt32 nLCID, String strWebTemplate, Boolean bCreateUniqueSubweb, Boolean bConvertIfThere, Guid appInstanceId)
   at Microsoft.SharePoint.SPWebCollection.Add(String strWebUrl, String strTitle, String strDescription, UInt32 nLCID, String strWebTemplate, Boolean useUniquePermissions, Boolean bConvertIfThere, Guid appInstanceId)
   at Microsoft.SharePoint.SPWebCollection_SubsetProxy.Add__Inner(String strWebUrl, String strTitle, String strDescription, UInt32 nLCID, SPWebTemplate_SubsetProxy WebTemplate, Boolean useUniquePermissions, Boolean bConvertIfThere)
   at Microsoft.SharePoint.SPWebCollection_SubsetProxy.Add(String strWebUrl, String strTitle, String strDescription, UInt32 nLCID, SPWebTemplate_SubsetProxy WebTemplate, Boolean useUniquePermissions, Boolean bConvertIfThere)
   at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at Microsoft.SharePoint.SPWebCollection_SubsetProxy.Add(String strWebUrl, String strTitle, String strDescription, UInt32 nLCID, SPWebTemplate_SubsetProxy WebTemplate, Boolean useUniquePermissions, Boolean bConvertIfThere)
   at Microsoft.SharePoint.SPWebCollection.Add__Inner(String strWebUrl, String strTitle, String strDescription, UInt32 nLCID, SPWebTemplate WebTemplate, Boolean useUniquePermissions, Boolean bConvertIfThere)
   at Microsoft.SharePoint.SPWebCollection.Add(String strWebUrl, String strTitle, String strDescription, UInt32 nLCID, SPWebTemplate WebTemplate, Boolean useUniquePermissions, Boolean bConvertIfThere)
   at O365.XproAS.ProjectLogEvents.ProjectLogEvents.CreatedWorkspace(SPItemEventProperties properties)

 

I also tried a Version where i checked if the web was actual in use;

 

                    SPWeb newWeb = null;

                    //foreach (SPWeb subWeb in wWeb.Webs)
                    //{
                    //    if (subWeb.Name == properties.ListItem[numb].ToString())
                    //        newWeb = subWeb;
                    //}

but it just gave me the same error.

What can be wrong?

br. H

January 23rd, 2014 4:09am

Hi,    

From the error message, there should be a site with the name "/project/space/7823-15152" exists.

What if you hardcode the parameters with some random strings and do the test, will this error occur?

I suggest that you can iterate through the sub sites to  see whether one name has been in use before the creating operation.

Feel free to reply if the error still exists.

Best regards
Free Windows Admin Tool Kit Click here and download it now
January 24th, 2014 1:49am

It does not exist.
The parameters for name is random

I also check for a existing web with same name before I try to add it.

For me it feels like some parallelle problem with SharePoint online , where it starts to add the SPWeb in different threads and crashes in the prosess..

Does anyone have working code for adding a SPWeb for SharePoint online.

January 24th, 2014 5:41am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics