Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Below iservice.svs.cs code how to use xml document in foreach class.is there any possible other way

iservice.cs


[ServiceContract]
public interface IService1
{
[OperationContract]
[WebInvoke(Method = "GET",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/GetAllEmployee/")]
List<Class1> GetAllEmployee();
}
<pre lang="cs">[DataContract]
public class Class1
{
[DataMember]
public string empid { get; set; }
[DataMember]
public string empname { get; set; }
[DataMember]
public string empage { get; set; }
[DataMember]
public string emplocation { get; set; }
}</pre>

iservice.svs.cs


<pre lang="xml">public class Service1 : IService1
{
public List&lt;Class1&gt; GetAllEmployee()
{

List&lt;Class1&gt; empList = new List&lt;Class1&gt;();



XmlDocument doc = new XmlDocument();
doc.Load(System.Web.HttpContext.Current.Server.MapPath(&quot;E:\\grid_wcf\\emp.xml&quot;));

foreach (var employee in employees)
{

empList.Add(new Class1
{
empid = employee.Element(&quot;empid&quot;).Value,
empname = employee.Element(&quot;empname&quot;).Value,
empage = employee.Element(&quot;empage&quot;).Value,
emplocation = employee.Element(&quot;emplocation&quot;).Value
});
}
return empList;
}



}</pre>
Posted
Comments
Richard Deeming 22-Jul-15 15:47pm    
You're passing a physical path to the Server.MapPath method. That method only accepts virtual paths.

Either pass a virtual path - eg: Server.MapPath("~/App_Data/emp.xml")
or use the physical path - eg: doc.Load("E:\\grid_wcf\\emp.xml")

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900