当前位置: 动力学知识库 > 问答 > 编程问答 >

WCF - reading an xml file in a service using XElement.Load

问题描述:

i have a simple xml file in a wcf service that i am trying to load using Xelement.Load("sample.xml") which is not reading the file. What's the right way of doing this?

The service is supposed to return an xml to an asp.net application.

TIA

网友答案:

I got it to work by providing the ABSOLUTE path as the parameter to the XElement.Load() method, RELATIVE path would be better though.

网友答案:

You should try something like this then.

var appPath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath; bodyFile = Path.Combine(appPath, @"<File Name Path");

This will work relative to your application's physical path.

分享给朋友:
您可能感兴趣的文章:
随机阅读: