Pages

Search This Blog

Friday, February 11, 2011

Reading XML Through Feature

In a scenario we have to create the whole site on the activation of feature, so for that we used a xml, which contains all the information regarding it.
This posts shows how we can read the xml (custom.xml) through feature, the custom.xml should be placed along with the feature.xml

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
XmlNodList objRootNode;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(properties.Definition.RootDirectory + "XML_FILE_NAME");
objRootNode = xmlDoc.SelectNodes("ChannelStaffing");
foreach (XmlNode objNode in objRootNode[0].ChildNodes)
{
foreach(XmlNode objChildNode in objNode.ChildNodes)
{
//Your code here
}
}
}

No comments:

Post a Comment