I am attempting to access a document library in a nested site http://sharepoint.abc.com/XXX/YYY/Test. XXX is a subsite of the root site collection (http://sharepoint.abc.com/) and YYY is a subsite of XXX. When I get an SPException (FAILED hr detected error code -2146232060 ("FAILED hr detected (hr = 0x80131904)") at SPDocumentLibrary documentLibrary = (SPDocumentLibrary)web.Lists[g_docLibName] in the following code block:
string g_siteUrl = "http://sharepoint.abc.com/XXX/YYY"; string g_docLibName = "Test"; SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(g_siteUrl)) { using (SPWeb web = site.OpenWeb()) { web.AllowUnsafeUpdates = true; SPDocumentLibrary documentLibrary = (SPDocumentLibrary)web.Lists[g_docLibName]; SPFileCollection files = documentLibrary.RootFolder.Files; SPFile newFile = files.Add(documentLibrary.RootFolder.Url + "/" + filename, file_bytes, true); ...
Therefore I attempted to open the subsite(web) another way but recieve the same SPException:
string g_siteUrl = "http://sharepoint.abc.com/"; string g_webURL = "XXX/YYY"; string g_docLibName = "Test"; SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(g_siteUrl)) { using (SPWeb web = site.OpenWeb(g_webURL)) { web.AllowUnsafeUpdates = true; SPDocumentLibrary documentLibrary = (SPDocumentLibrary)web.Lists[g_docLibName]; SPFileCollection files = documentLibrary.RootFolder.Files; SPFile newFile = files.Add(documentLibrary.RootFolder.Url + "/" + filename, file_bytes, true); ...
When I step through the code SPSite is returning the root site collection(SPSite URL=http://sharepoint.abc.com/) and all properties state "threw an exception of type Microsoft.SharePoint.SPException". The code is wrapped in a try but the catch is only triggered once the SPDocumentLibrary is instantiated.
Can someone please let me know what I am doing wrong here this should be a simple task. I have seen documented this way repeatedly. The path http://sharepoint.abc.com/XXX/YYY/Test/Forms/AllItems.aspx is a valid Document Library and is accessble. Any suggestions are appreciated. Thank you.
- Edited by JonesEJ20 Wednesday, October 02, 2013 12:32 AM Wrong