解析Xml文件并映射到SharePoint列表中的列

问题描述 投票:0回答:1

我有一个以下格式的XML文件。我有使用列URL,标题等创建的sharepoint列表。我需要使用CSOM将值从XML插入SP列表。有人可以建议一个代码。

<?xml version="1.0" encoding="UTF-8"?>

-<Sites>

-<Site xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<Url>https://ccepdev.sharepoint.com/sites/CCEP</Url>

<Title>CCEP</Title>

<WebTemplateTitle>Team site (classic experience)</WebTemplateTitle>

<WebTemplateName>STS#0</WebTemplateName>

<CreatedDate>2019-04-15T16:59:31+05:30</CreatedDate>

<LastItemModifiedDate>2019-04-23T13:26:55+05:30</LastItemModifiedDate>

<HasUniquePermissionValue>true</HasUniquePermissionValue>

<Description/>

<SiteCollectionUrl>https://ccepdev.sharepoint.com/sites/CCEP</SiteCollectionUrl>

<IsDeprecated>false</IsDeprecated>

<SubWebUrls/>

<ServerRelativeUrl>/sites/CCEP</ServerRelativeUrl>

<IsPublishingFeatureActivated>false</IsPublishingFeatureActivated>

<Language>1033</Language>

<IsNonDefaultMasterPage>false</IsNonDefaultMasterPage>

<CustomMasterPageUrl>/sites/CCEP/_catalogs/masterpage/seattle.master</CustomMasterPageUrl>

<MasterPageUrl>/sites/CCEP/_catalogs/masterpage/seattle.master</MasterPageUrl>

</Site>

</Sites>

---------------------------------------------------------------
xml sharepoint-online xmldocument xmlreader
1个回答
0
投票

使用Linq to XML选择节点/属性,然后通过CSOM添加到SharePoint。

XElement xmlFile = XElement.Load(@"C:\Lee\SiteData.xml");

            var data = from item in xmlFile.Descendants("Site")
                                          select new
                                          {
                                              ID = item.Element("Url").Value,
                                              Title = item.Element("Title").Value,
                                              WebTemplateTitle= item.Element("WebTemplateTitle").Value
                                              //more 
                                          };


using (var context = new ClientContext("https://tenant.sharepoint.com/sites/Developer"))
            {                 
                Console.ForegroundColor = ConsoleColor.Green;
                string password = "password";
                SecureString sec_pass = new SecureString();
                Array.ForEach(password.ToArray(), sec_pass.AppendChar);
                sec_pass.MakeReadOnly();
                context.Credentials = new SharePointOnlineCredentials("[email protected]", sec_pass);


                SP.List oList = context.Web.Lists.GetByTitle("listtitle");
                ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                ListItem oListItem = oList.AddItem(itemCreateInfo);
                oListItem["Title"] = data.Title;                

                oListItem.Update();

                context.ExecuteQuery();
}
© www.soinside.com 2019 - 2024. All rights reserved.