来源:自学PHP网 时间:2015-04-14 14:51 作者: 阅读:次
[导读] Add Script Editor Web Part :I had coding a function about adding scripteditorwebpart to page, here is the examplt to call function:AddScriptEditorWebPart http: localhost...
Add Script Editor Web Part :
I had coding a function about adding scripteditorwebpart to page, here is the examplt to call function:
AddScriptEditorWebPart "http://localhost" "/SitePages/Home.aspx" "JSFile.js"
function AddScriptEditorWebPart($siteUrl, $pageUrl, $jsLink){ $webPartProperty_Visible = $true $web = get-spweb $siteUrl $defaultPage = $web.GetFile($pageUrl) # Get the LimitedWebPartManager $webpartmanager=$defaultPage.GetLimitedWebPartManager([System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared) #Create fancy GUID $lvwpGuid1 = [System.Guid]::NewGuid().ToString() $lvwpKey = "g_" + $lvwpGuid1.Replace("-","_") # Instantiate wp $lvwp =New-Object Microsoft.SharePoint.WebPartPages.ScriptEditorWebPart $lvwp.ID = $lvwpKey $code = "$" $lvwp.Content = @" <script src="http://code.jquery.com/jquery-2.0.3.min.js" ></script> <script type="text/javascript" src="$jsLink"></script> "@ $lvwp.Title = "DocumentReadyForNewOrUpdatePost" $lvwp.Visible = $webPartProperty_Visible $lvwp.ChromeType = "None" $lvwp.HorizontalAlign = "Center" # Add the web part $webpartmanager.AddWebPart($lvwp, "Main", 0); # Update the web $web.Update(); write-host "success" $web.Dispose() write-host "Done" }
Add Content Editor Web Part :
AddScriptEditorWebPart "http://localhost" "/SitePages/Home.aspx" "file.txt"
function AddContentEditorWebPart($siteUrl, $pageUrl, $conetntLink){ $webPartProperty_Visible = $true $web = get-spweb $siteUrl $defaultPage = $web.GetFile($pageUrl) # Get the LimitedWebPartManager $webpartmanager=$defaultPage.GetLimitedWebPartManager([System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared) #Create fancy GUID $lvwpGuid1 = [System.Guid]::NewGuid().ToString() $lvwpKey = "g_" + $lvwpGuid1.Replace("-","_") # Instantiate wp $lvwp =New-Object Microsoft.SharePoint.WebPartPages.ContentEditorWebPart $lvwp.ID = $lvwpKey $code = "$" $lvwp.ContentLink = @" $conetntLink "@ $lvwp.Title = "DocumentReadyForNewOrUpdatePost" $lvwp.Visible = $webPartProperty_Visible $lvwp.ChromeType = "None" $lvwp.HorizontalAlign = "Center" # Add the web part $webpartmanager.AddWebPart($lvwp, "Main", 0); $web.Update(); $web.Dispose() }
|
自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习
京ICP备14009008号-1@版权所有www.zixuephp.com
网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com