473,388 Members | 1,215 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

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 3566
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bonzo | last post by:
Hi, How do I simply open a text file into a textbox? I know that in C++ I'd use something like: if(OpenDialog1->Execute()) Memo1->Lines->LoadFromFile(OpenDialog1->FileName); How can I do it...
3
by: michael haller | last post by:
In my project i have a textfile witch i import in my c# application. The datas in the textfile i show the datas in the textfile in my datagrid..ok that ist not my problem. Now i have a...
6
by: chau_fai | last post by:
I have a window Form called "Form2". There is only one button and a panel returned from a static method of the "Coord" in this form. In the panel returned, there is a button that can choose image...
3
by: bobrad | last post by:
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...
4
by: Nagachandra Sekhar Grandhi | last post by:
I am facing a problem with OpenFileDialog. It is as follows. I opened OpenFileDialog dialog box and selected a folder in it. After selecting the folder when i tried to delete the same folder in...
5
by: Sonia Igla | last post by:
Hi. I use in my windows c# project External Dlls(Assembly.LoadFrom(dllName);...). All work fine. I add to one of my forms using of OpenFileDialog. First time I call this form It works. Next...
0
by: Ion | last post by:
Hi, I have a ListView that is filled with selected paths from OpenFileDialog. Some times ListView is not redraw after OpenFileDialog close. I tried to fill paths to ListBox. I got the same...
4
by: bbembi_de | last post by:
Hello everyone, I have a C# program that runs a batch from the command line. I use the following code for that: String arguments = "/C CALL batchfile.bat"; ProcessStartInfo startInfo = new...
0
by: pyda001 | last post by:
Hi yall! I have created an image selection dropdown editor for use in a PropertyGrid. My selector form is called dropdown by a IWindowsFormsEditorService and so far it's all sweet. On my...
11
by: kimiraikkonen | last post by:
Hi, Vb.net 2005 express i've been working, the problem is: I use openfiledialog to browse files, i created some code to execute file with OK button, no problem. But if i press "cancel" button as...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.