Reputation: 1809
I have two projects in my solution, ProjectA and ProjectB. ProjectA contains folder named 'Config' which contains myfile.xml
.
I want to access this file from ProjectB which is a WebAPI
.
I tried following code:
string rootPath = System.Web.Hosting.HostingEnvironment.MapPath("~\\Config\\myfile.xml");
But It couoldn't retrieve ProjectA instead it made the following Path:
D:\Projects\DGS.DGSAPI.UI\ProjectB\Config\AffiliateInformationCollection.xml
instead of
D:\Projects\DGS.DGSAPI.UI\ProjectA\Config\AffiliateInformationCollection.xml
What am I doing wrong?
Upvotes: 1
Views: 959
Reputation: 392
as your running project is B the root of it is you ProjectB folder: string rootPath = System.Web.Hosting.HostingEnvironment.MapPath("~"); indeed return the root folder of ProjectB not your solution.
you can: have myfile.xml become a resource of projectA so it will be accessible and included in the dll.
point your ProjectA in web.config and read it there.
user a virtual folder.
I would use a resource if you need only this file, a web.config key if you need the folder.
Upvotes: 1