my combobox is populated with
6.70_Extensions
7.00_Extensions
7.10.000_Tip
7.10_Extensions
if my combobox selected value is 6.70_Extensions
and during a button event, how do i select a path from an xml file (antcheckin.xml) with "6.70_Extensions"
? for example: selecting "C:\\Work\\6.70_Extensions\\folder"
from an xml file.
note: The combobox selected value is
var buildStream =((DataRowView)BuildstreamComboBox.SelectedItem).Row["value"].ToString()
Basically after selecting this path, i am going to make this folder non-readonly.
So this is what i have done previously(note: this combo box was intially not populated with xml data and i managed to populate it with xml data and hence i need a new code for this below as i cannot depend on selected index now).
// 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>
EDIT 1: Hi guys, i will be doing a search into my antcheckin.xml file but i am kind of stuck to get parse the attribute out:
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?
}
Make use of LINQ TO XML and do search attribute valut in you xml
something as below
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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.