从内部文件夹ASP.NET问题使用Server.Mappath [英] ASP.NET Server.Mappath problem from inner folders

查看:110
本文介绍了从内部文件夹ASP.NET问题使用Server.Mappath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET应用程序凡在我APP_ code文件夹我有一个class.In,我有以下的code阅读这是我的根文件夹

I have an ASP.NET application where in my APP_Code folder i have a class.In that i have the following code to read the content of an XML file which is in my root folder

XmlDocument xmlSiteConfig = new XmlDocument();
xmlSiteConfig.Load(System.Web.HttpContext.Current.Server.MapPath("../myConfig.xml"));

我的根文件夹是具有与some.From嵌套内部的文件夹文件夹的第一级时,我打电话在App code级片code的,我能够加载XML文件几个文件夹正确,因为路径correct.Now如果我叫从肠子文件夹中的同一块code的,我。如果我改变code将低于它会正常工作收到错误

My Root folder is having several folders with nested inner folders for some.From the first level of folders when i call the piece of code in the Appcode class,I am able to load the XML file correctly since the path is correct.Now if i call the same piece of code from an innner folder,I am getting an error .If i change the code to the below it will work fine

xmlSiteConfig.Load(System.Web.HttpContext.Current.Server.MapPath("../../myConfig.xml"));

我该如何解决this.I不想为各种调用的文件路径更改为这个code.只嵌入哪块code的,我可以解决这个问题,使该程序将不考虑加载XML文件的通话位置。有什么建议?

How can i solve this.I dont want to change the file path for various calls to this code.With what piece of code I can solve the issue so that the program will load the XML file irrespective of the calling position . Any advice ?

在此先感谢

推荐答案

如果它的根文件夹,使用:

If it's in the root folder, use this:

Server.MapPath("~/myConfig.xml")

这将工作从任何目录。

这篇关于从内部文件夹ASP.NET问题使用Server.Mappath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆