'Open file dialog freezes the program when I try to use it
I am using visual studio 2017 to create a windows form application, which I am trying to use OpenFileDialog to load an XML file. When I first created the program everything works fine but after working and testing my code the application freezes when I launch the event to show the dialog.
I had this problem before where I was using Visual Studio 2015 and I could not find a solution.
public Form1()
{
InitializeComponent();
}
private void btnLoad_Click(object sender, EventArgs e)
{
if (ofdLoadXMLFile.ShowDialog() == DialogResult.OK)
{
string fileName = ofdLoadXMLFile.SafeFileName;
MessageBox.Show(fileName);
lblFileName.Text = fileName;
File.Copy(ofdLoadXMLFile.FileName, fileName);
XmlDocument document = new XmlDocument();
string _byteOrderMarkUtf8 = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble());
document.LoadXml(fileName.ToString());
string jsonText = JsonConvert.SerializeXmlNode(document);
string result = document.ToString();
File.WriteAllText(@"C:\Users\Connect To All\Desktop\result.json", jsonText);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
