首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >解析Xml文件并映射到SharePoint列表中的列

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

Stack Overflow用户
提问于 2019-04-24 22:03:55
回答 1查看 125关注 0票数 0

我有一个如下格式的XML文件。我有创建的sharepoint列表与列URL,标题等。我需要插入的值从XML到SP列表使用CSOM。有没有人能建议一个密码。

代码语言:javascript
复制
<?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>

---------------------------------------------------------------
EN

回答 1

Stack Overflow用户

发布于 2019-04-25 09:27:06

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

代码语言:javascript
复制
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("lee@tenant.onmicrosoft.com", 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();
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55831998

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档