Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!

I am working on windows application . I have an xml file for configuration ,I have added two project in the same solution ,I want to access the same xml file from the both project by using relative path . How I can do this

I have xml file name TeacherCongig.xml, I have added this file as a link in the second project and i am using
this code for accessing the linked file

string appPath = Path.GetDirectoryName(Application.ExecutablePath);
ds.ReadXml(appPath + "\\AppConfig\\TeacherConfig.xml");

give exception file not found.



Please help me!
Posted
Updated 25-Apr-11 20:34pm
v2
Comments
Sandeep Mewara 26-Apr-11 2:08am    
Do it, you know and as said using 'relative path'. What is the issue?

You can always add the same file to the other project as "a shortcut link".
When you add an existing file, just say add as shortcut.

Whatever changes you make in the first file then obviously get included in the second project.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 26-Apr-11 2:14am    
This is correct, but the naming is a bit different, so OP could be mislead. Also, you need to explain that at least once the item should be added via "Add", not "Add as Link", otherwise there will be a maintainability problem -- "original" (not "linked as") file won't be a part of any project. So, my 4 this time.

Please see my answer where I put it more accurately.
--SA
Abhinav S 26-Apr-11 2:16am    
That is what I meant. :)
Thanks for the 4.
Sergey Alexandrovich Kryukov 26-Apr-11 2:24am    
You could clarify this little detail to avoid any confusion...
--SA
MauryaArunKumar 26-Apr-11 2:20am    
It added successfully but not accessible from the second project!
Abhinav S 26-Apr-11 2:57am    
Just adding to the first project will not help.
You need to add a "file as link" in the second project.
If my answer is not clear, see SA's answer as well - he explains the steps in more detail.
Same solution or not — does not essentially matter (but better be neatly positioned withing the solution sub-directory.

Here is what to do: add a file using "Add"... "Existing item". The file will be copied is some solution folder. If you use "New Item", it will be created.

In another project, do "Add"... "Existing item", open it as you just did, but while in a Open File dialog, the button "Add" has two options controlled by a small arrow: "Add" or "Add as Link". Select "Add as Link". The file logically will be in two projects, but in one project it will be added as a relative file name (relative to the project file), in another one — as a linked "external" file, by relative path relative to another project file. Physically, this is the same file. Exactly as planned. :-)


—SA
 
Share this answer
 
v2
Comments
Abhinav S 26-Apr-11 2:16am    
I gave a 4 this time since this is essentially the same answer (but worded differently :))
Sergey Alexandrovich Kryukov 26-Apr-11 2:23am    
OK, Abhivav, but I did not copy anything. I created original answer at the same time as you, only it took a bit more time to type... :-) You are free to put any vote of course, I just see your reason is not correct. If somebody put a correct answer a bit later, I always trust it was independent and put my vote based on the value exclusively. And you're talking as if I just "re-worded" something. No.
--SA
Abhinav S 26-Apr-11 2:55am    
I know you did not copy or "reword" anything. So don't worry about that.
I just felt it was similar to mine and thus a 4 this time.
why not just use Application.StartupPath as the AppPath

C#
ds.ReadXml(Application.StartupPath + "\\AppConfig\\TeacherConfig.xml");
 
Share this answer
 
v2

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