Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Collection was modified; enumeration operation may not execute. while creating folders programmatically

$
0
0

hi,

i was creating the folder within a doc lib   with the below code, but i am getting the below error:

using (SPSite objchildsite = new SPSite(singleWeb.Url))
                {
                    using (SPWeb objchildweb = objchildsite.OpenWeb())
                    {

                        objchildweb.AllowUnsafeUpdates = true;

                        string objchildsweburl = objchildweb.Url;

                        if (objchildweb.Lists.Count > 0)
                        {
                            foreach (SPList singlelist in objchildweb.Lists)
                            {
                                if (singlelist.BaseType == SPBaseType.DocumentLibrary)
                                {
                                    SPDocumentLibrary bifSingleDocLib = singlelist as SPDocumentLibrary;
                                    if (bifSingleDocLib.IsCatalog == false)
                                    {
                                      var restriFolderrVar=   bifSingleDocLib.Items.Add("", SPFileSystemObjectType.Folder, restrictedFolderName);
                                      restriFolderrVar.Update();
                                      var nonrestrVar=   bifSingleDocLib.Items.Add("", SPFileSystemObjectType.Folder, non_restrictedFolderName);
                                      nonrestrVar.Update();
                                    }
                                }
                            }
                        }
                        objchildweb.AllowUnsafeUpdates = false;
                    }
                }

Collection was modified; enumeration operation may not execute.


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>