Skip to content

OpenFileDialog & write to XML Problem

jason

Asked Jul 26, 2009, 5:39 PM EDT1 answer
Share
LinkedInX
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.show() line and 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 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(fileNameTo Add .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

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/39cbc46a-2ad5-4300-8f08-4ca1469d6f76/ Found my answer: DialogAddTo.RestoreDirectory = true; added that line before .showDialog() and it fixed the problem...
    0