473,320 Members | 1,848 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,320 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 3555
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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.