S
shapper
Hello,
I having the following code to get some values from an XML file using
LINQ:
public List<string> GetDistricts() {
XDocument assets = XDocument.Load(Server.MapPath("Data/
Assets.xml"));
var districts = (from d in assets.Descendants("district")
select d).ToList();
return districts;
}
I am getting two errors:
1. The name 'Server' does not exist in the current context.
(I can't find the namespace where Server.MapPath is ... isn't
System.Web?)
2. Cannot implicitly convert type
'System.Collections.Generic.List<System.Xml.Linq.XElement>' to
'System.Collections.Generic.List<string>'
All I want is to create a list of string with the districts. And my
XML is something as follows:
<districts>
<district>First District</district>
<district>Second District</district>
</districts>
How can I solve these two problems?
Thanks,
Miguel
I having the following code to get some values from an XML file using
LINQ:
public List<string> GetDistricts() {
XDocument assets = XDocument.Load(Server.MapPath("Data/
Assets.xml"));
var districts = (from d in assets.Descendants("district")
select d).ToList();
return districts;
}
I am getting two errors:
1. The name 'Server' does not exist in the current context.
(I can't find the namespace where Server.MapPath is ... isn't
System.Web?)
2. Cannot implicitly convert type
'System.Collections.Generic.List<System.Xml.Linq.XElement>' to
'System.Collections.Generic.List<string>'
All I want is to create a list of string with the districts. And my
XML is something as follows:
<districts>
<district>First District</district>
<district>Second District</district>
</districts>
How can I solve these two problems?
Thanks,
Miguel