Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, June 28, 2013 3:05 PM
Hello all,
I am building an application that will allow my user to change their password. Their password will be stored in an XML Document. Also, I plan on doing password reset based off of secret questions, stored in an XML document. My code steps-through without error, but the XML document remains unchanged.
In my properties for the XML file, I have tried to set "Copy to output" as "Copy Always", and "Copy if Newer", no luck.
My code for saving is as below:
XmlDocument XMLdoc = new XmlDocument();
string XMLfilename = "PasswordHoldDoc.xml";
XMLdoc.Load(XMLfilename);
XmlNode root = XMLdoc.DocumentElement;
String pwdNode = root.FirstChild.InnerText;
//XmlNode pwdNode = XMLdoc.SelectSingleNode("/directory/password");
if (pwdNode != null)
{
root.FirstChild.InnerText = passwordConfirmTextbox.Text;
XMLdoc.Save("PasswordHoldDoc.xml");
MessageBox.Show("done!");
-JG
All replies (11)
Friday, June 28, 2013 3:37 PM
You do not set a save location, so it will save in the same folder as the executing assembly, probably bin/debug. If you have it set to copy to output then it is probably overwriting it everytime you build.
Try saving to a different folder, just to see if you code is even working. Something like c:\testfolder\PasswordHold.xml".
Lastly, XDocument, in the System.Xml.Linq namespace is easier to use and a more preferred namespace than XMLDocument.
Bob - www.crowcoder.com
Sunday, June 30, 2013 12:16 AM
Hey Bob,
Sorry for the lag in response, but I was able to successfully save when pointing to the alternate location. What do you suggest I do to resolve this?
-JG
Sunday, June 30, 2013 7:03 AM
you remove the location in your codes. Like below:
XmlDocument XMLdoc = new XmlDocument();
string XMLfilename = "PasswordHoldDoc.xml";
XMLdoc.Load(XMLfilename);
XmlNode root = XMLdoc.DocumentElement;
String pwdNode = root.FirstChild.InnerText;
//XmlNode pwdNode = XMLdoc.SelectSingleNode("/directory/password");
if (pwdNode != null)
{
root.FirstChild.InnerText = passwordConfirmTextbox.Text;
// Only use Save method,
XMLdoc.Save();
MessageBox.Show("done!");
If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. My sample
Sunday, June 30, 2013 12:49 PM
Hey Bob,
Sorry for the lag in response, but I was able to successfully save when pointing to the alternate location. What do you suggest I do to resolve this?
-JG
Do not set it to copy to output. Just manually drop that file into the Debug folder once and it will be there for you to load and overwrite.
When you make a release build, you can set it to copy, or again just copy manually before gathering up the files for delivery.
Bob - www.crowcoder.com
Monday, July 1, 2013 2:25 AM
I'll give this a try, and then get back to you.
-JG
Monday, July 1, 2013 2:55 AM
No luck,
The method has to have a file name as a parameter...
I have also tried to manually copy the file to the debug folder which gave an IO "file being used by another process" error, but I'll continue to fiddle with that a little more
-JG
Monday, July 1, 2013 11:23 AM
Don't try to copy the file to the Debug folder while your app is running.
Bob - www.crowcoder.com
Wednesday, July 3, 2013 1:31 PM
I indeed have copied the file while the application was not running, this error still comes up.
Thursday, July 4, 2013 6:33 AM
Hi JG525,
Would you mind upload a test sample to the SkyDrive and share the link here for us please? Thanks.
Bob Shen
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Tuesday, July 9, 2013 1:40 PM
Hello All, Bob S - There is no longer a need to upload - I was able to resolve the I\O error. Now I am back to the original error of the file being present in the bin\debug folder, and in the main project folder, with the code stepping through the xmldoc.save(xmldocumentname)without error, but never modifying the document in either location.
Tuesday, July 9, 2013 1:41 PM
Apologies Learning hard,
Thanks for your input in this!