I am sharing simple code to create List from xml file using the ASP.Net C#.
try
public static List<State> GettimeZoneByState(string StateCode)
{
{
XDocument doc =
XDocument.Load(System.Web.HttpContext.Current.Server.MapPath("~/Content/States.xml"));
var stateCodeData = doc.Root.Elements("state");
var timezone = stateCodeData.Select(a => new State{
StateName = a.Element("name").Value,
StateName = a.Element("name").Value,
StateCode = a.Element("abbreviation").Value,
TimeZone2 = a.Element("time-zone-2").Value,
Timezone = a.Element("time-zone-1").Value
}).Distinct().ToList();
}).Distinct().ToList();
return timezone;
}
catch
{
throw;
}
}
No comments:
Post a Comment