1
votes

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?

1
I believe you have to have a copy of myfile.xml in ProjectB. As your ProjectB would be running as a standalone instance on the web server, it will only have access within its own domain. In other words, ProjectB will not be aware of ProjectA unless ProjectA is added as a dependency in ProjectB.Azaz ul Haq

1 Answers

1
votes

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.