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

Need to set a breakpoint at SPList docLibrary = websiteCollection.Lists[docLibraryName]; to avoid System.IO.FileNotFoundException

$
0
0

While programming SP 2013 I have the following issue: I need to set a breakpoint at the "SPList docLibrary = websiteCollection.Lists[docLibraryName];" line to avoid getting a "FileNotFound" exception. If I set a breakpoint at the line and hit "continue" in the debugger the moment the breakpoint hits, everything works fine.

 If I run the code without the breakpoint, it cannot find the list, if I run the code with the breakpoint at the line, it finds the list fine and the code executes as it was intended. It looks like the statement "SPWeb websiteCollection = sharePointtopLevelSite.OpenWeb("sites/collection");" does complete before all the work is done, or something. I tried adding a Thread.Sleep in between but that didn't fix the problem.

using (SPSite sharePointtopLevelSite = new SPSite("http://mysite")) { sharePointtopLevelSite.AllowUnsafeUpdates = true; sharePointtopLevelSite.CatchAccessDeniedException = false; SPWeb websiteCollection = sharePointtopLevelSite.OpenWeb("sites/collection"); websiteCollection.AllowUnsafeUpdates = true; // Get document library for this project SPList docLibrary = websiteCollection.Lists["doclib"]; // bp here

:

}

This is the exception received:

System.IO.FileNotFoundException was caught
  HResult=-2147024894
  Message=<nativehr>0x80070002</nativehr><nativestack></nativestack>There is no Web named "/sites/collection".
  Source=""
  StackTrace:
       at Microsoft.SharePoint.Library.SPRequestInternalClass.GetListsWithCallback(String bstrUrl, Guid foreignWebId, String bstrListInternalName, Int32 dwBaseType, Int32 dwBaseTypeAlt, Int32 dwServerTemplate, UInt32 dwGetListFlags, UInt32 dwListFilterFlags, Boolean bPrefetchMetaData, Boolean bSecurityTrimmed, Boolean bGetSecurityData, Boolean bPrefetchRelatedFields, ISP2DSafeArrayWriter p2DWriter, Int32& plRecycleBinCount)
       at Microsoft.SharePoint.Library.SPRequest.GetListsWithCallback(String bstrUrl, Guid foreignWebId, String bstrListInternalName, Int32 dwBaseType, Int32 dwBaseTypeAlt, Int32 dwServerTemplate, UInt32 dwGetListFlags, UInt32 dwListFilterFlags, Boolean bPrefetchMetaData, Boolean bSecurityTrimmed, Boolean bGetSecurityData, Boolean bPrefetchRelatedFields, ISP2DSafeArrayWriter p2DWriter, Int32& plRecycleBinCount)
       at Microsoft.SharePoint.SPListCollection.EnsureListsData(Guid webId, String strListName)
       at Microsoft.SharePoint.SPListCollection.EnsureListsData(String strListName)
       at Microsoft.SharePoint.SPListCollection.GetListByName(String strListName, Boolean bThrowException)
       at Microsoft.SharePoint.SPListCollection.get_Item(String strListName)
       at UploadRecord.Uploader.Add(Collection`1 records) in c:\Users\Administrator.PREVIEW\Desktop\UploadRecord\UploadRecord\Uploader.cs:line 170
  InnerException: 

Any suggestions on how to bypass this issue? Adding a Thread.Sleep() didn't address the problem so it is maybe not a timing issue.










Viewing all articles
Browse latest Browse all 7589

Trending Articles



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