2011-04-18 62 views
0

我的組合框填充得到的XML文件的路徑

6.70_Extensions

7.00_Extensions

7.10.000_Tip

7.10_Extensions

如果我的ComboBox中選定值6.70_Extensions並在按鈕事件期間,我如何從xml文件(antcheckin.xml)中選擇一個路徑與"6.70_Extensions"?例如:從xml文件中選擇"C:\Work\6.70_Extensions\folder"

注:ComboBox中選定值

var buildStream =((DataRowView)BuildstreamComboBox.SelectedItem).Row["value"].ToString()

基本上選擇這條道路後,我打算將這個文件夾非只讀。因爲這是我以前做過的(注意:這個組合框沒有填充xml數據,我設法用xml數據填充它,因此我需要一個新的代碼,因爲我不能依賴於選定的現在索引)。

// the following is used to ensure the folder checked out is now not "read only" 


if (BuildstreamComboBox.SelectedIndex == 0) 
     { 
      var di = new DirectoryInfo("C:\\Work\\6.70_Extensions\\folder"); 
      foreach (var file in di.GetFiles("*", SearchOption.AllDirectories)) 
       file.Attributes &= ~FileAttributes.ReadOnly; 
     } 
     if (BuildstreamComboBox.SelectedIndex == 1) 
     { 
      var di = new DirectoryInfo("C:\\Work\\7.00_Extensions\\folder"); 
      foreach (var file in di.GetFiles("*", SearchOption.AllDirectories)) 
       file.Attributes &= ~FileAttributes.ReadOnly; 
     } 
     if (BuildstreamComboBox.SelectedIndex == 2) 
     { 
      var di = new DirectoryInfo("C:\\Work\\7.10.000_Tip\\folder"); 
      foreach (var file in di.GetFiles("*", SearchOption.AllDirectories)) 
       file.Attributes &= ~FileAttributes.ReadOnly; 
     } 

antcheckin.xml:

<project> 
    <buildmachine4> 
      <checkout1 exe="wco" folder='-f -R "C:/Work/6.70_Extensions/folder/"'/> 
      <checkout2 exe="wco" folder='-f -R "C:/Work/7.00_Extensions/folder/"'/> 
     </buildmachine4> 
     <buildmachine5> 

     <checkout3 exe="wco" folder='-f -R "C:/Work/7.10.000_Tip/folder/"'/> 
    </buildmachine5> 

</project> 

編輯1:傢伙嗨,我會做一個搜索到我的antcheckin.xml文件,但我有點陷進去出不來解析屬性:

public void BuildButton_Click(object sender, RoutedEventArgs e) 
{ 
    // the following is used to ensure the folder checked out is now not "read only" 

    // load your XML 
    XDocument doc = XDocument.Load(@"C:\Work\ANTCheckIN.xml"); 


    XElement mainItem = doc.Descendants("project") 
        .Where(mi => mi.Attribute("folder").Value.Contains(buildStream) 

    .... 
    //what should be added here? 
} 

回答

0

。利用LINQ的XML並做搜索屬性valut在你的XML

下面的東西

from el in root.Elements("rootlement") 
where 
(from add in el.Descendants() 
where 
add.Attribute("MyAttribute") != null 
&& 
add.Attribute("MyAttribute").Value.Contains("ZXCV") 
select add) 
.Any() 
select el; 
+0

但是我怎麼才能得到C:/Work/6.70_Extensions/folder?因爲它前面有'-f'和'-R' – jeremychan 2011-04-18 06:17:46

+0

@jeremychan - 通過字符串操作函數替換屬性 – 2011-04-18 06:28:34

+0

@jeremychan後可以編輯XML文件嗎?這些標誌是必要的嗎?如果是的話,我會建議你從文件夾屬性中分出'-f'和'-R'標誌。例如,像這樣的事情(我已經假定了標誌的含義):' '。 – bcpettifer 2011-04-18 11:54:59