# openFileDialog with writing a Dataset to .xml

**URL:** <https://forum.kirupa.com/t/openfiledialog-with-writing-a-dataset-to-xml/293293>\
**Category:** programming\
**Created:** [July 27, 2009, 1:17am UTC](https://forum.kirupa.com/t/openfiledialog-with-writing-a-dataset-to-xml/293293 "2009-07-27T01:17:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasonmc86](https://avatars.discourse-cdn.com/v4/letter/j/ecd19e/32.png) [@jasonmc86](https://forum.kirupa.com/u/jasonmc86)\
**Post date:** [July 27, 2009, 1:17am UTC](https://forum.kirupa.com/t/openfiledialog-with-writing-a-dataset-to-xml/293293/1 "2009-07-27T01:17:41Z")

</div>

Hey there,

What i’m trying to do is to select a file using a openFileDialog in visual c# using visual studio 2008 and then reading the file directory, file name and current date/time to an xml file, however the instance of the openFileDialog stops any writing of xml files for some reason.

Has any one got any Advice, here is my code:

You’ll notice that there’s no error however it doesnt write an xml file, but when i comment out the dialogAddTo.showDialog() line and associates and then change string filenameToAdd = “E:\blah\” or what ever it does write a xml file so im like wtf. Help would be appreciated

oh DialogAddTo is my openFileDialog, viwDataDS is the dataset and imagesTable is the datatable in the dataset

```auto

        private void btnAddImage_Click(object sender, EventArgs e)
        {
            try
            {
                switch (tabControlSelector.TabPages[tabControlSelector.SelectedIndex].Text)
                {
                    case "Images":
                        DialogAddTo.Title = "Add Image to Dir to view";
                        DialogAddTo.InitialDirectory = "E:\\Images\\";
                        DialogAddTo.Filter = "JPG| *.jpg";
                        DialogAddTo.Multiselect = false;
                        DialogResult result = DialogAddTo.ShowDialog();
                        String fileNameToAdd = DialogAddTo.FileName;
                        DialogAddTo.Dispose();
                        if (result == DialogResult.OK)
                        {
                            viwDataDS.imagesTable.AddimagesTableRow(fileNameToAdd .Substring(line.LastIndexOf("\\") + 1).ToString(),
                                fileNameToAdd .ToString(),
                                DateTime.Now);
                            viwDataDS.imagesTable.WriteXml("test.xml", XmlWriteMode.WriteSchema);
                        }
                        break;
                    case "Videos":
                        break;
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }

        }

```

Cheers Much Appreciated

Jason
