error when load xml file from sharepoint library - InfoPath Dev
in

InfoPath Dev

error when load xml file from sharepoint library

Last post 02-28-2007 03:00 PM by Anonymous. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 02-28-2007 01:49 PM

    error when load xml file from sharepoint library

    Hi everybody,

    I try to load an xml file stored in a sharepoint library, but I give an (401) Unauthorized error.
    My form is fully trusted and signed with my server's certificate. I'am login with administrator rights.

    When I push a button on my form, this following method try to load my xml, but the error occurs :
    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.Load("http://server/site/library/file.xml");

    No problem to load this file from my file system, but I really need to load it from this library.
    Is it possible to pass my credentials to resolve this case ?
    Or is there any other way to load this XML file ?
  • 02-28-2007 03:00 PM In reply to

    Re: error when load xml file from sharepoint library

    I've found a solution to my problem. See below the code to load an Xml file with Default Credentials :

    //create an XmlUrlResolver with default credentials
    XmlUrlResolver resolver=new XmlUrlResolver();
    resolver.Credentials=System.Net.CredentialCache.DefaultCredentials;

    //create an XmlTextReader to read the main xml file
    XmlTextReader mainTxtReader=new XmlTextReader("http://server/site/library/fichier.xml");
    mainTxtReader.XmlResolver=resolver;

    //load main Xml document
    XmlDocument xmlDoc = new XmlDocument();
    try{ xmlDoc.Load(mainTxtReader); }
    catch(System.IO.FileNotFoundException e){thisXDocument.UI.Alert("Could not load XML " + e.Message);}


    In Framework 2.0 it's better to use this following method to create the XmlReader :
    XmlReaderSettings settings = new XmlReaderSettings();
    settings.XmlResolver = resolver;
    XmlReader reader = XmlReader.Create("http://serverName/data/books.xml");
Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.