jason

jason

  • NA
  • 5
  • 4.5k

openFileDialog & write to XML Problem

Jul 26 2009 9:39 PM
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

Answers (1)