select xml tag and run the .exe
Currently i am running this in my UI. This happens during a button event:
wco "C:\folder1\"
In the above code, i am executing wco.exe followed by the folder name.
so my question is, is it possible to do this instead:
- click on button
- open an xml file
- get the code from an xml element
- run the code
so my xml file would look something like this:
<main>
<versions>
<version1>wco "C:\folder1\"</version1>
</versions>
</main>
if so how do i go about doing this?
EDIT 1:
This is how i run my code at the moment:
private void tab1nextButton_Click(object sender, RoutedEventArgs e)
{
string antText = "-f -R \"C:\\folder1\"";
System.Diagnostics开发者_如何学JAVA.Process.Start("wco", antText);
}
where -f and -R are just some parameters
You could use Linq to Xml like this (add your error handling, and GUI):
var x = XElement.Load(@"c:\temp\config.xml");
var xElement = x.Element("versions").Element("version1");
var p = new Process
{
StartInfo =
new ProcessStartInfo(xElement.Attribute("exe").Value,
xElement.Attribute("arguments").Value)
};
p.Start();
with a slightly modified config to help with parsing:
<main>
<versions>
<version1 exe="wco" arguments="C:\folder1\" />
</versions>
</main>
精彩评论