我有一个如下格式的XML文件。我有创建的sharepoint列表与列URL,标题等。我需要插入的值从XML到SP列表使用CSOM。有没有人能建议一个密码。
<?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>
---------------------------------------------------------------
发布于 2019-04-25 09:27:06
使用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("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();
}
https://stackoverflow.com/questions/55831998
复制相似问题