我的组合框填充得到的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?
}
但是我怎么才能得到C:/Work/6.70_Extensions/folder?因为它前面有'-f'和'-R' – jeremychan 2011-04-18 06:17:46
@jeremychan - 通过字符串操作函数替换属性 – 2011-04-18 06:28:34
@jeremychan后可以编辑XML文件吗?这些标志是必要的吗?如果是的话,我会建议你从文件夹属性中分出'-f'和'-R'标志。例如,像这样的事情(我已经假定了标志的含义):' '。 –
bcpettifer
2011-04-18 11:54:59