I've been getting a list of folders and files from Sharepoint (on Office 365) by using the following C# code...
... var folders = ListFolders(libraryName, clientContext, web); ... public List<Folder> ListFolders(string libraryName, ClientContext clientContext, Web web) { var list = GetDocumentLibrary(libraryName, clientContext, web); var folders = list.RootFolder.Folders; clientContext.Load(folders); clientContext.ExecuteQuery(); return folders.ToList(); } public List GetDocumentLibrary(string libraryName, ClientContext clientContext, Web web) { var query = clientContext.LoadQuery(web.Lists.Where(p => p.Title == libraryName)); clientContext.ExecuteQuery(); return query.FirstOrDefault(); }
It was working fine until I rebooted my computer (it installed a Windows Update), I strongly suspect, based on some testing I've done, it is caused by http://support.microsoft.com/kb/2964358
When the *clientContext.ExecuteQuery()* statement is reached in *GetDocumentLibrary()*, the
following exception is thrown.
*An unhandled exception of type 'System.Xml.XmlException' occurred in System.Xml.dll
Additional information: For security reasons DTD is prohibited in this XML document. To enable DTD processing set the DtdProcessing property on XmlReaderSettings to Parse and pass the settings into XmlReader.Create method.*
I'm wondering how I can work around this, as I'm not consciously using System.XML, it's a background function or process when the ExecuteQuery runs.
Can I pass some additional XMLReader info to this or clientContext (I'm assuming not), so I'm not sure how to execute this query to prevent the DTD error. I have also tried accessing the list in a different manner, by using this code... (from Microsoft's MSDN
pages)
List list = clientContext.Web.Lists.GetByTitle(libraryName);
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View/>";
ListItemCollection listItems = list.GetItems(camlQuery);
clientContext.Load(list); clientContext.Load(listItems);
clientContext.ExecuteQuery();
This works on a computer without the KB above, however on my PC it doesn't (I get the same exception as my other code) , obviously uninstalling the KB will make things work in the short term, but its no good in the longer term. Any advice on how to avoid this error would be greatly appreciated. I can only assume there will be a "preferred" way from Microsoft for accessing lists now this KB is implemented, but I'm clueless as to what it is.
Thanks
Dougie