Я новичок в LINQtoXML. Я хочу использовать метод XElement.Load (""). но компилятор не может найти мой файл. можете ли вы помочь мне написать правильный путь для моего XML-файла? Обратите внимание: я определил класс в App_Code, и я хочу использовать данные файла XML в одном из методов и в файле XML. Он находится в App_Data.
XElement.Load ("~/App_Data/file.xml") Не удалось найти часть пути
settings = XElement.Load("App_Data/AppSettings.xml");
я не могу использовать Request.ApplicationPath
и Page.MapPath()
или Server.MapPath()
, чтобы получить физический путь для моего файла, потому что я не нахожусь в классе Наследуется класса формы страницы.
Краткое сообщение об ошибке:
Не удалось найти часть пути 'C: \ Program Files \ Microsoft Visual Studio 9.0 \ Common7 \ IDE \ App_Data \ AppSettings.xml'.
вы видите путь скомпилирован полностью отличается от моего пути проекта (G: \ MyProjects \ ASP.net Projects \ VistaComputer \ Сайт \ App_Data \ AppSettings.xml)
Полная Сообщение об ошибке здесь:
System.IO.DirectoryNotFoundException was unhandled by user code
Message="Could not find a part of the path 'C:\\Program Files\\Microsoft Visual Studio 9.0\\Common7\\IDE\\App_Data\\AppSettings.xml'."
Source="mscorlib"
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
at System.Xml.XmlReader.Create(String inputUri, XmlReaderSettings settings, XmlParserContext inputContext)
at System.Xml.XmlReader.Create(String inputUri, XmlReaderSettings settings)
at System.Xml.Linq.XElement.Load(String uri, LoadOptions options)
at System.Xml.Linq.XElement.Load(String uri)
at ProductActions.Add(Int32 catId, String title, String price, String website, String shortDesc, String fullDesc, Boolean active, Boolean editorPick, String fileName, Stream image) in g:\MyProjects\ASP.net Projects\VistaComputer\Website\App_Code\ProductActions.cs:line 67
at CMS_Products_Operations.Button1_Click(Object sender, EventArgs e) in g:\MyProjects\ASP.net Projects\VistaComputer\Website\CMS\Products\Operations.aspx.cs:line 72
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:
большое спасибо. Полезно. – mahdiahmadirad
+1 Спасибо! Это было именно то, что я искал. – devios1