Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I want to query and existing sharepoint view. Is this possible? I did not find any tutorial to guide for querying a view.How cant it be done? Kindly tell me is this possible or not and if yes than how?

share|improve this question

migrated from stackoverflow.com Oct 2 '12 at 19:18

This question came from our site for professional and enthusiast programmers.

    
Could you please try to rephrase your question? It is difficult to understand what you are trying to accomplish. –  Robert Kaucher Oct 2 '12 at 19:29

2 Answers 2

up vote 2 down vote accepted

I believe this is what you are looking for

Sorry for the powershell snippet, but it will be easy to test and easy to convert for usage in other api's

# Add SharePoint PowerShell Snapin
if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) {
    Add-PSSnapin Microsoft.SharePoint.Powershell
}

$web = Get-SPWeb "http://url"
$listName = "List Name"
$list = $web.Lists[$listName]

$viewName = "View name" 
$view = $list.Views[$viewName]
## Or get by view id
#$viewId = "A6932332-765A-4776-A1DF-18016DA1D645"
#$view = $list.GetView($viewId)

$query = New-Object Microsoft.SharePoint.SPQuery
$query.ViewAttributes = "Scope=""Recursive"""
$query.ViewXml = '<View><Query>' + $view.Query + '</Query></View>'

$items = $list.GetItems($query)
$items.Count

$web.Dispose()
share|improve this answer
    
This should be the correct answer, you can indeed query a SharePoint List View. –  Paul Leigh Dec 3 '13 at 13:51

You cannot query a list view.

A Sharepoint list view - can be create by definitions or by the web UI.

You dont "query" views, you use them to display list information.

You need to be more clearer with what you are asking.

regards, KS

share|improve this answer
1  
This should really be a comment. –  Robert Kaucher Oct 2 '12 at 19:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.