1

I'm trying to read a simple XML document into memory using Linq.

But when I try to use the XElement.Load method, Visual Studio doesn't seem to recognize it at all.

I've imported the System.Linq and System.Xml.linq libraries but .load just doesn't work.

Framework used is ".NET 3.5".

What silly detail am I overlooking? Code below in case it helps.

using System.Linq;
using System.Xml.Linq;
using System.Xml.XPath;

...

    private void AddTechHours(string Locatie, DateTime StartTijd, DateTime EindTijd, TimeSpan TotaalTijd)
    {
        XElement Doc = new XElement.Load(Locatie);
        XElement Hours = new XElement("Line",
                new XElement("S_Code", null),
                new XElement("S_Artikel", "URE000099999"),
                new XElement("S_Omschr", "Totaal Uren Mekanieker"),
                new XElement("S_Aantal", TotaalTijd.Hours),
                new XElement("S_Stockpl", "1"),
                new XElement("S_Srtregel", "2"),
                new XElement("S_Vanuur", StartTijd.ToString("HH:mm")),
                new XElement("S_Totuur", EindTijd.ToString("HH:mm")),
                new XElement("S_Vankm", null),
                new XElement("S_Totkm", null),
                new XElement("S_Reflev", null),
                new XElement("S_Artcode", null),
                new XElement("S_Levdat", DateTime.Now.ToString("yyyyMMdd")));
        Doc.Add(Hours);
        Doc.Save(Locatie);            
    }

2 Answers 2

3

Load is a static method, try this :

XElement Doc = XElement.Load(Locatie);
1
  • 1
    I can't believe I didn't notice that... Thank you for your help Joffrey, much appreciated.
    – Hetiwos
    Jun 10, 2013 at 8:17
2

The Load method of XElement is static and cannot be called on instances.

Change your code to the following and it will work

XElement Doc = XElement.Load(Locatie);

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.