C# 读取XML属性 更新到SharePoint 2013 中
public void UpdateSharePointListFromXML() { string filename = Server.MapPath("XMLFile1.xml"); XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(filename); XmlNodeList topM = xmldoc.DocumentElement.ChildNodes; foreach (XmlElement element in topM) { if (element.Name == "ISA_Info") { Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(delegate() { SPSite site = new SPSite("http://jack-7716f30e37:2012"); using (SPWeb web = site.OpenWeb()) { web.AllowUnsafeUpdates = true; site.AllowUnsafeUpdates = true; SPList list = web.Lists["MyList"]; SPListItem Item = list.Items.Add(); Item["field"] = element.Attributes[0].Value.ToString(); Item["Value"] = element.Attributes[1].Value.ToString(); Item.Update(); list.Update(); } }); } } }
<?xml version="1.0" encoding="utf-8" ?> <ISA xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ISA_Info field="ISA.FullPath" value="\\nas\apps\test\PDF\AKF000210460100051.pdf"/> <ISA_Info field="ISA.Customer" value="Test Customer"/> <ISA_Info field="ISA.Type" value="AKF"/> <ISA_Info field="Meta.Categorie" value="INS"/> <ISA_Info field="Meta.Doc.Date" value="08/06/2010"/> <ISA_Info field="Meta.FileNumber" value="021046"/> <ISA_Info field="Meta.Year" value="2010"/> <ISA_Info field="Meta.Description" value=" Installatie P360 scanner"/> </ISA>