Add Script Editor and Content Editor Web Part via powershell
2013-09-26 15:19
489 查看
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() }
相关文章推荐
- Add/Remove listview web part in publish site via powershell
- Add/Remove listview web part in publish site via powershell
- Add custom and listview web part to a page in wiki page using powershell
- Add custom and listview web part to wiki page using powershell
- Add/Delete ContentType in list via powershell
- Gitosis and Gitweb – Part 2 – Add Projects and Contributors
- Configuring and Customizing the Content Query Web Part(转http://blogs.msdn.com/b/ecm/archive/2006/10/
- 关于loadrunner使用web_add_header添加HTTP信息头(比如Content-Type,token等)和使用web_custom_request()提交json数据
- CS001497 - Add data to a web page with JavaScript, WebKit, and Qt
- 如何在SharePoint中配置和自定义Content Query Web Part(一)
- XenDesktop 5 PowerShell SDK Primer – Part 2 – Creating Hypervisor Connections and Hosts
- web.config add handlers and httpmodule to System.Web section.
- How to: Add SharePoint 2010 Search Web Parts to Web Part Gallery for Upgraded Site Collections
- Useful info about sharepoint security and web part creation
- How to Configure Selenium Webdriver in Eclipse and execute some simple test script.
- The Difference Between “Add Web Reference” and “Add Service Reference”
- A Web-based Rich Content Editor that works on Opera
- 试用FP4中的web(click and script)协议(简单的录制)
- 如何在SharePoint中配置和自定义Content Query Web Part(一)
- 解决 Unable to add dynamic content. A script attempted to inject dynamic content, or elements previous