开发者

select xml tag and run the .exe

开发者 https://www.devze.com 2023-02-23 06:18 出处:网络
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.

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:

  1. click on button
  2. open an xml file
  3. get the code from an xml element
  4. 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>
0

精彩评论

暂无评论...
验证码 换一张
取 消