I want to make a button that
I've made a button like this:
private void button1_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog fDialog = new OpenFileDialog();
fDialog.Title = "Open XML file";
fDialog.Filter = "XML files|*.config";
fDialog.InitialDirectory = @"C:\";
fDialog.ShowDialog();
}
I already made a method that reads from hard-coded location, but can someone help me about that file path part variable?
Method reads file with XmlTextReader like this:
private void ReadAdvancedConfigFile()
{
XElement root = null;
root = XElement.Load(new XmlTextReader(@"C:\Users\nemanja.mosorinski\Downloads\__Research-master\__Research-master\SEDMSVSPackage\VisualStudioPackage\AppRes\ConfigFiles\Unity.config"));
}
So basically I want to put new file path for some file founded by OpenFileDialog in root variable.
Change this line:
fDialog.ShowDialog();
To:
bool? control = fDialog.ShowDialog();
if(control.Value)
{
var filePath = fDialog.FileName;
ReadAdvancedConfigFile(filePath)
}
Also you should change the method signature
private void ReadAdvancedConfigFile(string path)