I have a function that creates an empty folder when called. It usually works fine. But it only fails once throwing this error -
Microsoft.SharePoint.SPException ---> System.Runtime.InteropServices.COMExceptio
n: <nativehr>0x80131904</nativehr><nativestack></nativestack>
at Microsoft.SharePoint.Library.SPRequestInternalClass.AddOrUpdateItem(String
bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPre
serveItemVersion, Boolean bPreserveItemUIVersion, Boolean bUpdateNoVersion, Int3
2& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bst
rVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& p
varProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bUnRestrictedUpdateI
nProgress, Boolean bMigration, Boolean bPublish, String bstrFileName, ISP2DSafeA
rrayWriter pListDataValidationCallback, ISP2DSafeArrayWriter pRestrictInsertCall
back, ISP2DSafeArrayWriter pUniqueFieldCallback)
at Microsoft.SharePoint.Library.SPRequest.AddOrUpdateItem(String bstrUrl, Str
ing bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVers
ion, Boolean bPreserveItemUIVersion, Boolean bUpdateNoVersion, Int32& plID, Stri
ng& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Obj
ect& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties
, Boolean bCheckOut, Boolean bCheckin, Boolean bUnRestrictedUpdateInProgress, Bo
olean bMigration, Boolean bPublish, String bstrFileName, ISP2DSafeArrayWriter pL
istDataValidationCallback, ISP2DSafeArrayWriter pRestrictInsertCallback, ISP2DSa
feArrayWriter pUniqueFieldCallback)
--- End of inner exception stack trace ---
at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx)
at Microsoft.SharePoint.Library.SPRequest.AddOrUpdateItem(String bstrUrl, Str
ing bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVers
ion, Boolean bPreserveItemUIVersion, Boolean bUpdateNoVersion, Int32& plID, Stri
ng& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Obj
ect& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties
, Boolean bCheckOut, Boolean bCheckin, Boolean bUnRestrictedUpdateInProgress, Bo
olean bMigration, Boolean bPublish, String bstrFileName, ISP2DSafeArrayWriter pL
istDataValidationCallback, ISP2DSafeArrayWriter pRestrictInsertCallback, ISP2DSa
feArrayWriter pUniqueFieldCallback)
at Microsoft.SharePoint.SPListItem.AddOrUpdateItem(Boolean bAdd, Boolean bSys
tem, Boolean bPreserveItemVersion, Boolean bNoVersion, Boolean bMigration, Boole
an bPublish, Boolean bCheckOut, Boolean bCheckin, Guid newGuidOnAdd, Int32& ulID
, Object& objAttachmentNames, Object& objAttachmentContents, Boolean suppressAft
erEvents, String filename, Boolean bPreserveItemUIVersion)
at Microsoft.SharePoint.SPListItem.UpdateInternal(Boolean bSystem, Boolean bP
reserveItemVersion, Guid newGuidOnAdd, Boolean bMigration, Boolean bPublish, Boo
lean bNoVersion, Boolean bCheckOut, Boolean bCheckin, Boolean suppressAfterEvent
s, String filename, Boolean bPreserveItemUIVersion)
at Microsoft.SharePoint.SPListItem.Update()
at MigrateSite.Program.AddDummyFolderInRoot(String siteUrl, String libraryNam
e, String folderName) in c:\Users\svcmmo13farm_dev\Source\Repos\MigrateSite\Migr
ateSite\Program.cs:line 784
My code is as follows:
public static void AddDummyFolderInRoot(string siteUrl, string libraryName, string folderName)
{
using(SPSite site = new SPSite(siteUrl))
{
using(SPWeb web = site.OpenWeb())
{
try
{
web.AllowUnsafeUpdates = true;
web.Update();
SPList lib = web.Lists.TryGetList(libraryName);
SPListItem dummyFolder = lib.AddItem(lib.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder, folderName);
dummyFolder.Update();
lib.Update();
web.Update();
}
catch (Exception e)
{
Console.WriteLine("error:\n"+e);
Console.ReadKey(true);
}
}
}
}
Could you help me out? Thanks
PS: I am working with Sharepoint 2013.