Query only approuved files

Hello everyone,

Today I will talk about a little trick that a friend gave me recently.

Having used to work with SPQuery, I was already familiar with the attribute needed to query all the file within list’s folder:

 SPQuery.ViewAttributes = "Scope='Recursive'"; 

But recently I learned of another attribute to filter only on documents approved! Indeed there is an attribute “ModerationType” !

 SPQuery.ViewAttributes = " ModerationType='HideUnapproved'"; 

And so if we want to make our request only on our approved documents, we will add the following attributes to our SPQuery.

 SPQuery.ViewAttributes = "Scope='Recursive' ModerationType='HideUnapproved'"; 

Hope this helps!



2 thoughts on “Query only approuved files

  1. sanjay rimal

    This is good steven I was basically wondering if I could just query a particular view instead of applying filterin my scenario people are changing filter criteria so frequent so I don’t want people monkeying around the code. Thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s