Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I have a solution which is having multiple projects. One of the projects is having an XML file with predefined values. Now, I want to access these values from another project, but same solution.

How can I access it?

What I have tried:

XDocument proxyXML = XDocument.Load("~//project1.Common.Model//valueSettings.xml");
Posted
Updated 28-Jun-17 1:38am
Comments
Richard MacCutchan 27-Jun-17 11:50am    
Just change the path to refer to the correct file location.

Put the .xml file in your main solution folder and reference it from your projects by right-clicking and selecting "add to project", then right click the file and in the properties set "Copy to output directory" to always.
If you want to avoid unneccesary copies, you can choose "Add as link".
 
Share this answer
 
v2
Comments
sopi9 28-Jun-17 3:41am    
There are multiple projects in a single solution. This XML is in one of the project(Say project name is common), but, I want to access it through all the projects.
I have added reference of this common project in all other projects. Also, I have set "Copy to output directory" to always. Now this XML will be in a bin of Common project. How can I access bin path of this Common project in another projects.
I am able to access bin path of current folder but not sure about accessing bin path of another project
RickZeeland 28-Jun-17 4:44am    
If your "Common" project has the .xml file included with "Copy to output directory" and you reference the "Common" project from your other projects, the .xml file should also be copied to the other bin folders with all files of the "Common" project.
sopi9 28-Jun-17 7:25am    
Its not possible to copy XML to other bin folders. This xml file is central repository for common values(accessible/used by all other projects).
So, these common values accessible to all the projects will modified dynamically and stored in this XML.
As per your solution, keeping copy of xml in all the bin folders, these xml files may not have the latest updated data.
Every time XML in common project is updated, I had to copy this updated file to all the bin folder a runtime, which will be an overhead.
To get the path where the exe is:
C#
string strPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
strPath = strPath.Replace(@"file:\\", string.empty);
Then replace the project name with @"project1.Common.Model"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900