Click here to Skip to main content
15,889,211 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a XML file in my XBAP project which is accessed by classes in it.I am able to get the path of file using
C#
System.IO.Path.Combime(AppDomain.CurrentDomain.BaseDirectory, @"Filename.xml")

and access it using
C#
XDocument.Load(ObtainedPath)

For some reason when I publish my project it does not work and adds a path to the AppData folder and throws an

C#
System.Windows.Markup.XamlParseException


I have also tried to changed the properties of file to

BuildAction: Content and Copy to Output Directory: Copy Always

and tried to make a direct access, this too does not work. Can someone please help me find a way to access the file when it is published?

Thanks
Posted
Updated 28-May-15 11:34am
v5
Comments
ZurdoDev 28-May-15 17:05pm    
What error do you get?
Member 10794476 28-May-15 17:15pm    
It Gives me System.Windows.Markup.XamlParseException. Path.Combine() adds a path to AppData\Local\Apps\2.0\..... to the existing file when the project is published, works well otherwise.

1 solution

Tyr getting the path of the deployment folder something like this.

System.Deployment.Application.ApplicationDeployment.CurrentDeployment

used namespace - System.Deployment.dll

Then used following steps to get the directory name

var datadir = System.Deployment.Application.ApplicationDeployment.CurrentDeployment.DataDirectory

deployment folder path should be something
C:\Users\Administrator\AppData\Local\Apps\2.0\Data\BVPTZA5G3AC\WC2WBZ92.D96\ expe..tion_ba14dd6bedbd6876_0000.0009_7919ca38a4e51341\Data\1.0.0.0

and used this path to get the xml file, I suppose then you can load your xml file.

Hope this helps this help.
 
Share this answer
 
Comments
Member 10794476 28-May-15 18:02pm    
It works!! Thanks a lot.
Hussain Patel 28-May-15 22:25pm    
you are welcome..

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