I'm trying to open an XML file from my document library. I'm running some code as "Elevated Privilege" on a file I know exists.
The code I wrote down is this:
SPSecurity.RunWithElevatedPrivileges(() =>
{
using (SPSite sito = new SPSite("SITE URL"))
{
using (SPWeb web = sito.OpenWeb())
{
SPList lista = web.Lists.TryGetList("DOCUMENT LIBRARY NAME");
foreach (SPFile file in lista.RootFolder.Files)
{
String fileUrl = web.Url + "/" + lista.RootFolder.Url + "/" + file.Url;
var ret = XDocument.Load(fileUrl);
}
}
}
});
When I reach the XDocument.Load command I get the "401 Unauthorized" exception..
Is there something wrong with my code? Is XDocument running with wrong pribilege?
Thank you very much