Reputation: 229
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);
}
Upvotes: 1
Views: 565
Reputation: 35544
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);
Upvotes: 2
Reputation: 6499
Load is a static method, try this :
XElement Doc = XElement.Load(Locatie);
Upvotes: 3