Click here to Skip to main content
15,890,670 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, Here's my scenario, I have 1 XML file inside my project, the settings of the XML is Build Action: Content, Copy to output directory: Copy Always... the properties of my project for the config for Debug is Release not Debug, Everytime i run in debugging mode the application works fine, and XML file also includes in Bin Folder which is actually what i want.

and now After I publish the application it throws error unhandled exception has occured in your application "Could not find file C:\Users\Rence\Appdata\Local\Apps\2.0\J966MBXD.YRX\BH01TD0Y.208\...........So on\XML_File.xml'." Please help me to fix it i dont know what is wrong with my configuration


Here's my code to read the xml

C#
if (checkBox1.Checked == false)
           {
               metrobankcodetxtBox.Items.Clear();

               XmlDocument doc = new XmlDocument();
               doc.Load("XML_Lpnp_combo.xml");
               XmlNodeList nodeList = doc.SelectNodes("FPNP/FPNP_code");

               foreach (XmlNode node in nodeList)
                   if (!metrobankcodetxtBox.Items.Contains(node.SelectSingleNode("Code").InnerText))
                       metrobankcodetxtBox.Items.Add(node.SelectSingleNode("Code").InnerText);

           }
           else if (checkBox1.Checked == true)
           {
               metrobankcodetxtBox.Items.Clear();

               XmlDocument doc = new XmlDocument();
               doc.Load("XML_Lpnp_combo.xml");
               XmlNodeList nodeList = doc.SelectNodes("FPNP/FPNP_Codeup");

               foreach (XmlNode node in nodeList)
                   if (!metrobankcodetxtBox.Items.Contains(node.SelectSingleNode("Codeup").InnerText))
                       metrobankcodetxtBox.Items.Add(node.SelectSingleNode("Codeup").InnerText);
           }
Posted
Updated 24-Jan-16 21:18pm
v2
Comments
dan!sh 25-Jan-16 3:17am    
1. What is code you are using to read the file (just the line where you are specifying file path)
2. Are you shipping XML along with "publish"?
Rencyrence 25-Jan-16 3:20am    
what do you mean with shipping XML along with publish?
Rencyrence 25-Jan-16 3:19am    
Hello, Please check my updated question, i added codes to read the file
dan!sh 25-Jan-16 3:21am    
Do you have the file in same directory as the executable?
Rencyrence 25-Jan-16 3:23am    
Yes I have it

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