Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. # Add SharePoint PowerShell Snapin
  2. if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) {
  3. Add-PSSnapin Microsoft.SharePoint.Powershell
  4. }
  5.  
  6. $web = Get-SPWeb "http://url"
  7. $listName = "List Name"
  8. $list = $web.Lists[$listName]
  9.  
  10. $viewName = "View name"
  11. $view = $list.Views[$viewName]
  12. ## Or get by view id
  13. #$viewId = "A6932332-765A-4776-A1DF-18016DA1D645"
  14. #$view = $list.GetView($viewId)
  15.  
  16. $query = New-Object Microsoft.SharePoint.SPQuery
  17. $query.ViewAttributes = "Scope=""Recursive"""
  18. $query.ViewXml = '<View><Query>' + $view.Query + '</Query></View>'
  19.  
  20. $items = $list.GetItems($query)
  21. $items.Count
  22.  
  23. $web.Dispose()
  24.  
  25. using (SPSite siteColl = new SPSite("http://site_collection_URL"))
  26. {
  27. using (SPWeb site = siteColl.OpenWeb())
  28. {
  29. SPList list = site.Lists["list_name"];
  30. SPView view = list.Views["view_name"];
  31. SPQuery query = new SPQuery();
  32. query.ViewAttributes = "Scope="Recursive"";
  33. query.ViewXml = "<View><Query>" + view.Query + "</Query></View>";
  34.  
  35. SPListItemCollection results = list.GetItems(query);
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement