2

We currently have code like this:

Dim xDoc = XDocument.Load(myXMLFilePath)

The only way we know how to do it currently is by using a file path and impersonation (since this file is on a secured network path).

I've looked at XDocument.Load on MSDN, but I don't see anything.

3 Answers 3

5

I would suggest using a WebRequest to get a stream and load the stream into the document.

Sign up to request clarification or add additional context in comments.

1 Comment

I wonder what the difference in overhead is between opening a file over the network versus using a WebRequest...
4

That very documentation says that the file parameter is "A URI string that references the file to load into a new XDocument." Furthermore, I have code that does exactly that---uses XDocument.Load with a URI.

2 Comments

And by URI, you specifically mean a URL and not a file path? I haven't had any luck passing in a URL to XDocument.Load().
Yes, my code definitely passes in a URL, of the "stuff" type. And it works. Not sure what to tell you if you don't have any luck... :-|.
0
//Sample XML
<Product>
    <Name>Product1</Name>
    <Price>0.00</Price>
</Product>

    //Reading XML
    XmlTextReader rdr = new XmlTextReader("http://your-url");
    XDocument loaded = XDocument.Load(rdr);

    //View the loaded contents
    //Response.ClearHeaders();
    //Response.ContentType = "text/xml;charset=UTF-8";
    //Response.Write(loaded);
    //Response.End();

    var data = from c in loaded.Descendants("Product")
            select new
            {
                name = c.Element("Name").Value,
            price = c.Element("Price").Value,
        };

    foreach (var element in data)
    {
        //Do something here
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.