Download presentation
Presentation is loading. Please wait.
Published byGeorgiana Ellis Modified over 9 years ago
1
PS SharePoSH:\> http://www.SharePoSH.comhttp://www.SharePoSH.com @SharePoSH@SharePoSH SPListItem / SPFile SharePoint + PowerShell User Group March 27, 2013
2
PS SharePoSH:\> http://www.SharePoSH.comhttp://www.SharePoSH.com @SharePoSH@SharePoSH Agenda Hello! Group Logistics (GoToMeeting/ website / register / email / twitter) SPListItem / SPFile Next meeting Survey!
3
PS SharePoSH:\> http://www.SharePoSH.comhttp://www.SharePoSH.com @SharePoSH@SharePoSH Raymond Mitchell SharePoint Consultant – http://www.Rackspace.com http://www.Rackspace.com Author Dad Information Worker Kid – http://www.iwkid.com http://www.iwkid.com SharePoSHing since 2008 Hello!
4
PS SharePoSH:\> http://www.SharePoSH.comhttp://www.SharePoSH.com @SharePoSH@SharePoSH What about you?
5
PS SharePoSH:\> http://www.SharePoSH.comhttp://www.SharePoSH.com @SharePoSH@SharePoSH SPListItem List item Library item SPListItemCollection – SPList.Items
6
PS SharePoSH:\> http://www.SharePoSH.comhttp://www.SharePoSH.com @SharePoSH@SharePoSH SPListItem SPList.Items[5] Iterating by index can be VERY expensive
7
PS SharePoSH:\> http://www.SharePoSH.comhttp://www.SharePoSH.com @SharePoSH@SharePoSH SPListItem More ways to get items using SPList members – GetItems String[]items only with specific fields SPQueryitems by query SPViewitems by view SPQuery, Stringby query and view – GetItemsWithUniquePermissions
8
PS SharePoSH:\> http://www.SharePoSH.comhttp://www.SharePoSH.com @SharePoSH@SharePoSH SPListItem More ways to get items using SPList members – GetItemById & GetItemByIdAllFields – GetItemByIdSelectedFields – GetItemByUniqueId
9
PS SharePoSH:\> http://www.SharePoSH.comhttp://www.SharePoSH.com @SharePoSH@SharePoSH SPListItem Once you have an item: – SPList.Fields or SPListItem.Fields
10
PS SharePoSH:\> http://www.SharePoSH.comhttp://www.SharePoSH.com @SharePoSH@SharePoSH SPListItem Reading field values – Item[guid]Field’s id – Item[Int32]Field’s index – Item[String]Title or Internal Name But it isn’t always quite that easy...
11
PS SharePoSH:\> http://www.SharePoSH.comhttp://www.SharePoSH.com @SharePoSH@SharePoSH SPListItem Reading field values – SPFieldUser / SPFieldUserValue – SPFieldLookup / SPFieldLookupValue LookupId LookupValue $fieldName = "Assigned To" $f = $list.Fields[$fieldName] $fv = $f.GetFieldValue($item[$fieldName])
12
PS SharePoSH:\> http://www.SharePoSH.comhttp://www.SharePoSH.com @SharePoSH@SharePoSH SPListItem Similar for setting values $new = $list.Items.Add() $fv = new-object Microsoft.SharePoint.SPFieldUrlValue() $new["Search URL"] = $fv $new.Update()
13
PS SharePoSH:\> http://www.SharePoSH.comhttp://www.SharePoSH.com @SharePoSH@SharePoSH SPListItem Requires Update to commit – Update() – UpdateOverwriteVersion() – SystemUpdate(boolean) true = increment item version false = don’t update Modified or Modified By
14
PS SharePoSH:\> http://www.SharePoSH.comhttp://www.SharePoSH.com @SharePoSH@SharePoSH SPListItem Common Properties – Attachments – Fields – File / Folder – HasUniqueRoleAssignments Common Methods – BreakRoleInheritance – ResetRoleInheritance
15
PS SharePoSH:\> http://www.SharePoSH.comhttp://www.SharePoSH.com @SharePoSH@SharePoSH SPFile SPListItem.File SPFolder.Files – RootFolder property – SPWeb.GetFolder(string)URL of the folder SPWeb.GetFile(string) URL of the file
16
PS SharePoSH:\> http://www.SharePoSH.comhttp://www.SharePoSH.com @SharePoSH@SharePoSH SPFile Common Properties – Exists – ItemFile’s parent SPListItem – LengthFile size (in bytes) – Url
17
PS SharePoSH:\> http://www.SharePoSH.comhttp://www.SharePoSH.com @SharePoSH@SharePoSH SPFile Common Methods – CheckIn/CheckOut/Publish – CopyTo(string, bool) Destination and Overwrite – MoveTo – OpenBinary/OpenBinaryStream – SaveBinary/SaveBinaryStream
18
PS SharePoSH:\> http://www.SharePoSH.comhttp://www.SharePoSH.com @SharePoSH@SharePoSH SPFile Download files from SharePoint via SPFile (C#) $b = $file.OpenBinary() $fs = New-Object System.IO.FileStream("c:\temp\test.docx", "create", "readwrite") $bw = New-Object System.IO.BinaryWriter($fs) $bw.Write($b) $bw.Close() Just want a string? – SPWeb.GetFileAsString(string)URL
19
PS SharePoSH:\> http://www.SharePoSH.comhttp://www.SharePoSH.com @SharePoSH@SharePoSH Next Meeting TBD – Your Demos
20
PS SharePoSH:\> http://www.SharePoSH.comhttp://www.SharePoSH.com @SharePoSH@SharePoSH Resources PowerShell + SharePoint forum at PowerShell.org: – http://powershell.org/discuss/viewforum.php?f=1 2 http://powershell.org/discuss/viewforum.php?f=1 2 PowerShell Summit: April 22-24 http://powershell.org/summit http://powershell.org/summit
21
PS SharePoSH:\> http://www.SharePoSH.comhttp://www.SharePoSH.com @SharePoSH@SharePoSH Resources Save files from SharePoint document library to File System http://blogs.msdn.com/b/varun_malhotra/archive/2008/12/15/save-files-from- sharepoint-document-library-to-file-system.aspx http://blogs.msdn.com/b/varun_malhotra/archive/2008/12/15/save-files-from- sharepoint-document-library-to-file-system.aspx SPListItem http://msdn.microsoft.com/en- us/library/microsoft.sharepoint.splistitem(v=office.14).aspx http://msdn.microsoft.com/en- us/library/microsoft.sharepoint.splistitem(v=office.14).aspx SPFile http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfile(v=office.14).aspx http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfile(v=office.14).aspx
22
PS SharePoSH:\> http://www.SharePoSH.comhttp://www.SharePoSH.com @SharePoSH@SharePoSH Survey! http://sdrv.ms/YSM470
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.