Candy

:★..CANDY LOVE~。。●じ
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

关于Server端读xml并将其作为数据源的问题。

Posted on 2008-09-17 17:29  丽红  阅读(157)  评论(0编辑  收藏  举报

Question:

I am using the following code:

DataSet mydata = new DataSet();

mydata.ReadXml("~/App_Data/sdn.xml");

But instead of going to the App_Data directory of my web site (hosted on IIS on my local machine for test purposes), I get the error:

System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\WINDOWS\system32\~\App_Data\sdn.xml'.

Is there something I am missing? If I put the file into a different path and reference the path directly, the program works fine, but I need the service to look into the correct app_data directory to deploy to a remote web server.

 

Answer:

 

You should use the physical path while reading from a file.

DataSet mydata = new DataSet();

mydata.ReadXml(Server.MapPath("~/App_Data/sdn.xml"));

Hope this will help you.