asp.net MVC2 the absolute path method of obtaining files

Source: Internet
Author: User

Because the controller is placed in the class library in the MVC2 project, the parsing XML file is used, and the project structure is shown below

How to get the absolute path to the XML file in the class library, I searched the web

This method is used by Appdomain.currentdomain.basedirectory to get the base directory of the current application domain

Can you get it through Server.MapPath (), think about it and move your hands immediately.

First I referenced the SYSTEM.WEB.MVC in the class library and then in the Controller Class Server can write out, but MapPath not to come out, I wrote it on my own, the results reported a mistake

Error 1 Type "System.web.https tutorial Erverutilitybase" is defined in an assembly that is not referenced. You must add a reference to the assembly "System.web.abstractions, version=3.5.0.0, Culture=neutral, publickeytoken=31bf3856ad364e35".

Error 2 "System.web.httpserverutilitybase" does not contain the definition of "MapPath" and cannot find an extension method that accepts the first argument of type "System.web.httpserverutilitybase" MapPath "(is missing a using directive or an assembly reference?)

This error is obvious, haha immediately introduced system.web.abstractions

String xmlpath= this.server.mappath ("/files/xml/city.xml");

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.