PS SharePoSH:\> Web Parts! SharePoint + PowerShell User Group August 17, 2012 http://www.SharePoSH.com @SharePoSH PS SharePoSH:\> Agenda • Hello! • Group Logistics (Lync / website / register / email.

Download Report

Transcript PS SharePoSH:\> Web Parts! SharePoint + PowerShell User Group August 17, 2012 http://www.SharePoSH.com @SharePoSH PS SharePoSH:\> Agenda • Hello! • Group Logistics (Lync / website / register / email.

PS SharePoSH:\>
Web Parts!
SharePoint + PowerShell User Group
August 17, 2012
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
Agenda
• Hello!
• Group Logistics (Lync / website / register /
email / twitter)
• Web Parts!
• Useful Scripts
• Next meeting
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
Hello!
Raymond Mitchell
• SharePoint Consultant
– http://www.Rackspace.com
• Author
• Dad
• Information Worker Kid
– http://www.iwkid.com
• SharePoSHing since 2008
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
What about you?
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
Web Parts + PowerShell
•
•
•
•
•
•
•
•
•
Web Part Basics Review
Show all web parts in the gallery
SPLimitedWebPartManager
Different Web Part Classes
Adding a Web Part
Editing/Saving properties of a Web Part
Searching for Web Parts (closed/by type)
Export Web Parts
Web Part Page Web Service
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
Show all web parts in the gallery
• Open Web Part Gallery in browser, show
populate option
• Reflector:
Microsoft.SharePoint.ApplicationPages.NewD
wp
•
$web = Get-SPWeb http://localhost
$safe =
[Microsoft.SharePoint.ApplicationRuntime.SharePointHandler]::GetSafeControls($web)
$safe | % { $_.FullName; }
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
SPLimitedWebPartManager
• SPWeb.GetLimitedWebPartManager
• Scope – Shared or User
• FT Title, WebBrowsableObject
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
Common Web Part Classes
•
•
•
•
•
Microsoft.SharePoint.WebPartPages.XsltListViewWebPart
Microsoft.SharePoint.WebPartPages.ContentEditorWebPart
Microsoft.SharePoint.WebPartPages.ImageWebPart
Microsoft.SharePoint.WebPartPages.SimpleFormWebPart
Microsoft.SharePoint.Publishing.WebControls.MediaWebPa
rt
• Microsoft.SharePoint.Publishing.WebControls.ContentByQu
eryWebPart
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
New Web Part Page
$web = Get-SPWeb http://localhost
$pages = $web.Lists["Site Pages"]
$new =
[Microsoft.SharePoint.Utilities.SPUtility]::CreateNewWikiPage($p
ages, "SitePages/SharePoSH.aspx")
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
New XSLT List View Web Part
$web = Get-SPWeb http://localhost
$pages = $web.Lists["Site Pages"]
$wp = New-Object Microsoft.SharePoint.WebPartPages.XsltListViewWebPart
$wp.ListId = $pages.ID
$wp.ViewGuid = $pages.DefaultView.ID
$mgr = $web.GetLimitedWebPartManager("/SitePages/SharePoSH.aspx", "Shared")
$mgr.AddWebPart($wp, 0, 0)
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
New Form Part
$web = Get-SPWeb http://localhost
$mgr = $web.GetLimitedWebPartManager("/SitePages/SharePoSH.aspx", "Shared")
$fwp = New-Object Microsoft.SharePoint.WebPartPages.SimpleFormWebPart
$fwp.Content = "<b>Just testing a form</b>"
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
New CEWP
$web = Get-SPWeb http://localhost
$mgr = $web.GetLimitedWebPartManager("/SitePages/SharePoSH.aspx", "Shared")
$cewp = New-Object Microsoft.SharePoint.WebPartPages.ContentEditorWebPart
$xml = New-Object -TypeName xml
$xmlContent = $xml.CreateElement("Content")
$xmlContent.InnerText = "<b>Test!</b>"
$cewp.Content = $xmlContent
$mgr.AddWebPart($cewp, 0, 0)
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
Find Web Parts
$web = Get-SPWeb http://localhost
$mgr = $web.GetLimitedWebPartManager("/SitePages/SharePoSH.aspx", "Shared")
$mgr.WebParts | ? { $_.IsClosed -eq $true } | ft title, WebBrowsableObject
$mgr.WebParts | ? { $_.WebBrowsableObject.ToString().Contains("Form") }
| ft title, WebBrowsableObject
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
Export Web Part
$wp = $mgr.WebParts[0]
$sw = New-Object System.IO.StringWriter
$xw = [System.xml.XmlWriter]::Create($sw)
$mgr.ExportWebPart($wp, $xw)
$xw.Close()
$sw.Close()
$sw.ToString()
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
Web Services
• http://msdn.microsoft.com/enus/library/ms774747(v=office.12)
$proxy = New-WebServiceProxy http://localhost/_vti_bin/WebPartPages.asmx
$proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
$proxy.GetWebPartPage("/SitePages/SharePoSH.aspx", "Version3")
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
YOUR scripts!
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
Next Meeting
• Friday, September 14th
• Topics:
– Lists & views
– Publishing
– IIS / web.config
http://www.SharePoSH.com
@SharePoSH
PS SharePoSH:\>
Resources
• PowerShell + SharePoint forum at
PowerShell.org:
– http://powershell.org/discuss/viewforum.php?f=1
2
http://www.SharePoSH.com
@SharePoSH