使用电源外壳在线更新共享点的Web部件内容。

编程入门 行业动态 更新时间:2024-10-28 04:17:19
本文介绍了使用电源外壳在线更新共享点的Web部件内容。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好,

我想用(XML文件:已从一个内容编辑器文件导出)更新Web部件的内容

在线shell中没有 Webpart.content 的属性。在线更新它的什么是均衡属性?

[System.Reflection.Assembly] :: LoadWithPartialName(" Microsoft.SharePoint.Client") [System.Reflection.Assembly] :: LoadWithPartialName(" Microsoft.SharePoint.Client.Runtime") 函数New-Context( [String] $ WebUrl){ $ UserName =" testi@test123.onmicrosoft" ;; $ SecurePassword =" PASSWORD" | ConvertTo-SecureString -AsPlainText -Force $ context = New-Object Microsoft.SharePoint.Client.ClientContext($ WebUrl) $ context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($ UserName ,$ SecurePassword) $ context $ credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($ UserName,$ SecurePassword)} 函数Get- List([Microsoft.SharePoint.Client.ClientContext] $ Context,[String] $ ListTitle){ $ list = $ context.Web.Lists.GetByTitle($ ListTitle) $ context.Load($ list) $ context.ExecuteQuery() $ list } $ context = New-Context -WebUrl" test.sharepoint /位点/ testPortal /" $ list = Get-List -Context $ context -ListTitle" Pages" $ query = [Microsoft.SharePoint.Client.CamlQuery] :: CreateAllItemsQuery() $ items = $ list.GetItems($ query) $ context.Load($ item) $ context.ExecuteQuery() $ items.Count foreach($ item in $ items) { $ XMLFilePath =" C:\\\\testfile \" + $ item [" Title"] +" .xml" ;; $ URL = $ item.Context.Url +" Pages /" + $ item [" Title"] +" .aspx" write-host $ URL; $ page = $ Context.Web.GetFileByUrl($ URL) $ Context.Load($ page) $ Context.ExecuteQuery() $ webpartmanager = $ page.GetLimitedWebPartManager ([Microsoft.Sharepoint.Client.WebParts.PersonalizationScope] :: Shared) $ Context.Load($ webpartmanager) $ webParts = $ webpartmanager.WebParts $ Context.Load($ webParts ) $ Context.ExecuteQuery() #Create Root Elemment" pages" foreach($ webparts $ webparts) { $ NewWebPartXml = get-content $ XMLFilePath $ webPartXmlWP = $ webpartmanager.ExportWebPart($ webpart.Id) $ Context.ExecuteQuery() $ OldContentXml = $ webPartXmlWP.Value; #$ XmlDoc = New-Object System.Xml.XmlDocument #$ NewContentXml = $ XmlDoc.CreateElement(" Webpart")#$ NewContentXml.InnerText = $ OldContentXml .Replace($ OldContentXml,$ NewWebPartXml)#write-host $ NewContentXml.InnerText; #Set content and Save #$ webpart.Content = $ NewContentXml; #$ webpart.SaveWebPartChanges(); $ Context.Load($ webpart.WebPart.Properties) try { $ Context.executeQuery() write-host $ webpart.WebPart.Properties。 } catch { write-host" Error:$($ _.Exception.Message)" -foregroundcolor red } $ webpart.WebPart.Properties [" Content"] = $ NewWebPartXml; ====这里我收到错误==================== $ webpart.SaveWebPartChanges(); $ Context.executeQuery() } } $ context.Dispose()

解决方案

内容编辑器Web部件,没有Content属性,如果要设置此Web部件的内容,请在PowerShell中使用这样的文件URL直接设置ContentLink:

Add-Type -Path" C:\Program Files \Common Files \ Mysoftoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path" C:\Program Files \Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" 函数New-Context([String]

WebUrl){

UserName =" xxx@xxx.onmicrosoft .COM英寸;

Hi All,

I want to update the content of the web part with (XML File: which is already exported from one content editor file)

In power shell online there is no Property of Webpart.content. what is equalent property in online to update it?

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime") Function New-Context([String]$WebUrl) { $UserName = "testi@test123.onmicrosoft"; $SecurePassword = "PASSWORD" | ConvertTo-SecureString -AsPlainText -Force $context = New-Object Microsoft.SharePoint.Client.ClientContext($WebUrl) $context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword) $context $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword) } Function Get-List([Microsoft.SharePoint.Client.ClientContext]$Context, [String]$ListTitle) { $list = $context.Web.Lists.GetByTitle($ListTitle) $context.Load($list) $context.ExecuteQuery() $list } $context = New-Context -WebUrl "test.sharepoint/sites/testPortal/" $list = Get-List -Context $context -ListTitle "Pages" $query = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery() $items = $list.GetItems($query) $context.Load($items) $context.ExecuteQuery() $items.Count foreach($item in $items) { $XMLFilePath="C:\test\testfile\"+$item["Title"]+".xml"; $URL= $item.Context.Url+"Pages/"+$item["Title"]+".aspx" write-host $URL; $page = $Context.Web.GetFileByUrl($URL) $Context.Load($page) $Context.ExecuteQuery() $webpartmanager = $page.GetLimitedWebPartManager([Microsoft.Sharepoint.Client.WebParts.PersonalizationScope]::Shared) $Context.Load($webpartmanager) $webParts = $webpartmanager.WebParts $Context.Load($webParts) $Context.ExecuteQuery() #Create Root Elemment "pages" foreach($webpart in $webparts) { $NewWebPartXml = get-content $XMLFilePath $webPartXmlWP = $webpartmanager.ExportWebPart($webpart.Id) $Context.ExecuteQuery() $OldContentXml=$webPartXmlWP.Value; #$XmlDoc = New-Object System.Xml.XmlDocument #$NewContentXml= $XmlDoc.CreateElement("Webpart") #$NewContentXml.InnerText= $OldContentXml.Replace($OldContentXml, $NewWebPartXml) #write-host $NewContentXml.InnerText; #Set content and Save #$webpart.Content = $NewContentXml; #$webpart.SaveWebPartChanges(); $Context.Load($webpart.WebPart.Properties) try { $Context.executeQuery() write-host $webpart.WebPart.Properties. } catch { write-host "Error: $($_.Exception.Message)" -foregroundcolor red } $webpart.WebPart.Properties["Content"]=$NewWebPartXml; ====Here i am getting error==================== $webpart.SaveWebPartChanges(); $Context.executeQuery() } } $context.Dispose()

解决方案

Hi,

For a Content Editor Web Part, there is no Content property, if you want to set the Content of this web part, directly set the ContentLink with a file url like this in PowerShell:

Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" Function New-Context([String]

WebUrl) {

UserName = "xxx@xxx.onmicrosoft";

更多推荐

使用电源外壳在线更新共享点的Web部件内容。

本文发布于:2023-11-09 13:45:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572516.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:在线   部件   外壳   电源   内容

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!