470,625 Members | 2,060 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,625 developers. It's quick & easy.

PROBLEM WITH OpenFileDialog WITH XML

MAYBE SOMEBODY CAM HELP

I AM USING THE FOLLOWING CODE TO GET A LOCATION OF A FILE IN A WINFORM
DIALOG

OpenFileDialog openFileDialog = new OpenFileDialog();
OpenFileDialog.Filter = " Access (*.mdb)|*.mdb|All files (*.*)|*.*";
if (openFileDialog.ShowDialog() == DialogResult.OK)
DataBaseLocation.Text = openFileDialog.FileName;

THIS WORKS GREAT AND I GET THE LOCATION PUT IN A TEXT BOX
HERE COMES THE PROBLEM, I WANT TO SAVE THIS LOCATION IN AN XML FILE
(DOCUMENT) STORED ON THE PC. HERE GOES MY CODE FOR XML
XmlTextWriter TW=new XmlTextWriter("dbfile.xml",null);
TW.WriteStartDocument();
TW.WriteStartElement("Database");
TW.WriteElementString("DatabaseLoc",cf.DataBaseLoc ation.Text);
TW.WriteEndElement();
TW.WriteEndDocument();
TW.Close();

THIS CODE WORKS FINE ONLY IF I TYPE IN THE LOCATION INTO THE TEXTBOX
MSELF, I AM THAN ABLE TO CREATE AN XML FILE ON THE PC. IF I USE THE
OPENFILEDIALOG TO SELECT A FILE, THIS IS WHERE I HAVE THE PROBLEM.
FIRST IT DOES NOT CREATE A XMLFILE AT ALL EVEN THOGUH THE INFORMATION
SHOWS UP IN THE TEXT BOX, IF I CLOSE THIS DIALOG AND REOPEN IT GIVES
THE IMPRESSION IT READ THE XML FILE AND DISPLAY THE FILE I SELECTED
EVEN THOUGH THERE IS NO PHYSICAL XML FILE, IT APPEARS AS IF IT'S
STILL IN MEMORY AND NOT COMMITING THE WRITE. IF I EXIT THE
APPLICATION AND RESTART IT I CAN NO LONGER PULL UP THE XML FILE.

doES ANYONE HAVE ANY IDEA WHAT THE PROBOLE CODE BE, AM I USING A
REFERNCE RATHER THAN ACTUAL STRING, THATS WHY XML CAN'T COMMIT TO THE
WRITE? OR IS THIS A BUG? ANY HELP ON THIS WOULD BE GREAT

THANKS

Nov 16 '05 #1
1 3292
I was able to make it work with a minor change. I dropped cf in the line
below.
TW.WriteElementString("DatabaseLoc",cf.DataBaseLoc ation.Text);
If that does'nt work & you still think that the content in memory is not
being commited to a disk, try doing Flush() on the Writer.

-Naraen

-----
"bobrad" <bo*******@comcast-dot-net.no-spam.invalid> wrote in message
news:40********@127.0.0.1... MAYBE SOMEBODY CAM HELP

I AM USING THE FOLLOWING CODE TO GET A LOCATION OF A FILE IN A WINFORM
DIALOG

OpenFileDialog openFileDialog = new OpenFileDialog();
OpenFileDialog.Filter = " Access (*.mdb)|*.mdb|All files (*.*)|*.*";
if (openFileDialog.ShowDialog() == DialogResult.OK)
DataBaseLocation.Text = openFileDialog.FileName;

THIS WORKS GREAT AND I GET THE LOCATION PUT IN A TEXT BOX
HERE COMES THE PROBLEM, I WANT TO SAVE THIS LOCATION IN AN XML FILE
(DOCUMENT) STORED ON THE PC. HERE GOES MY CODE FOR XML
XmlTextWriter TW=new XmlTextWriter("dbfile.xml",null);
TW.WriteStartDocument();
TW.WriteStartElement("Database");
TW.WriteElementString("DatabaseLoc",cf.DataBaseLoc ation.Text);
TW.WriteEndElement();
TW.WriteEndDocument();
TW.Close();

THIS CODE WORKS FINE ONLY IF I TYPE IN THE LOCATION INTO THE TEXTBOX
MSELF, I AM THAN ABLE TO CREATE AN XML FILE ON THE PC. IF I USE THE
OPENFILEDIALOG TO SELECT A FILE, THIS IS WHERE I HAVE THE PROBLEM.
FIRST IT DOES NOT CREATE A XMLFILE AT ALL EVEN THOGUH THE INFORMATION
SHOWS UP IN THE TEXT BOX, IF I CLOSE THIS DIALOG AND REOPEN IT GIVES
THE IMPRESSION IT READ THE XML FILE AND DISPLAY THE FILE I SELECTED
EVEN THOUGH THERE IS NO PHYSICAL XML FILE, IT APPEARS AS IF IT'S
STILL IN MEMORY AND NOT COMMITING THE WRITE. IF I EXIT THE
APPLICATION AND RESTART IT I CAN NO LONGER PULL UP THE XML FILE.

doES ANYONE HAVE ANY IDEA WHAT THE PROBOLE CODE BE, AM I USING A
REFERNCE RATHER THAN ACTUAL STRING, THATS WHY XML CAN'T COMMIT TO THE
WRITE? OR IS THIS A BUG? ANY HELP ON THIS WOULD BE GREAT

THANKS

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Bonzo | last post: by
3 posts views Thread by michael haller | last post: by
6 posts views Thread by chau_fai | last post: by
3 posts views Thread by bobrad | last post: by
4 posts views Thread by Nagachandra Sekhar Grandhi | last post: by
5 posts views Thread by Sonia Igla | last post: by
reply views Thread by Ion | last post: by
4 posts views Thread by bbembi_de | last post: by
reply views Thread by pyda001 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.