in

Dot Net Mafia

Group site for developer blogs dealing with (usually) .NET, SharePoint 2013, SharePoint 2010, Office 365, SharePoint Online, and other Microsoft products, as well as some discussion of general programming related concepts.

This Blog

Syndication

Archives

Corey Roth [MVP]

A SharePoint MVP bringing you the latest time saving tips for SharePoint 2013, Office 365 / SharePoint Online and Visual Studio 2013.

Using search to find recently modified files in SharePoint 2010

Last week, I posted about how we can extend CoreResultsWebPart to show documents created by the current user.  Using this same technique, we can also use search to find recently modified documents.  If you are a long time follower of my blog, you might remember that I posted how to do with using the Wildcard Search Web Part in SharePoint 2007.  In an effort to keep posts updated, I thought I would post a follow up on how we can do the same thing in SharePoint 2010.  Since the CoreResultWebPart has changed quite a bit, the solution is quite a bit cleaner and still only requires two lines of code.  Again, we are going to create a web part that inherits from CoreResultsWebPart as described in my Wildcard Search Web Part for SharePoint 2010 post. 

The first thing we need to do is change the QueryNumber.  By default it is set to Query1 (or UserQuery back in 2007) which meant that it was expecting input from the user.  In this case, I just change it to Query2.

this.QueryNumber = QueryId.Query2;

Then we just need to construct a query using the Write keyword.  I’ve explained its use before in my handy keywords post.  It’s syntax is usually something like this.  Note that there are no spaces anywhere in the string below.

Write>=”12/1/2011”

Of course this would hard code the date and we don’t want that.  So what I do instead is use DateAdd and subtract a number of days.  In my case, I want to show all documents from the last seven days.  We assign this query to the FixedQuery property.  Here is what it looks like.

this.FixedQuery = string.Format("Write>=\"{0}\"", DateTime.Today.AddDays(-7));

Compile your code and deploy it and then you are good to go.  Just use this web part in lieu of the regularCoreResultsWebPart.  Here’s what it looks like on my page.

SearchRecentDocuments

That’s all there is to it.  One addition, you might want to make to your code is to allow the number of days to be user configurable.  You can easily make a web part property that allows the user to specify the number of days.

Comments

 

SharePoint Daily » Blog Archive » Measuring the Success of Your SharePoint Implementation; Should Gates Return to Microsoft?; Save 10% on Bamboo Suites said:

Pingback from  SharePoint Daily  » Blog Archive   » Measuring the Success of Your SharePoint Implementation; Should Gates Return to Microsoft?; Save 10% on Bamboo Suites

December 9, 2011 8:14 AM
 

SharePoint Daily said:

Friends don't let friends text and drive . - Dooley Top News Stories 5 Tips for Measuring the Success

December 9, 2011 8:20 AM
 

Sharepoint Updates December-09-2011 | SDavara's Sharepoint Knowledge Center said:

Pingback from  Sharepoint Updates December-09-2011 | SDavara's Sharepoint Knowledge Center

December 10, 2011 1:55 AM
 

Override Core Results Web Part With Custom Query « Sladescross's Blog said:

Pingback from  Override Core Results Web Part With Custom Query « Sladescross's Blog

December 14, 2011 11:39 AM
 

Override Core Results Web Part With Custom Query « Sladescross's Blog said:

Pingback from  Override Core Results Web Part With Custom Query « Sladescross's Blog

December 14, 2011 11:39 AM
 

Mario said:

Hi Corey, we tried to create a similar page. But we have tried to use response headers as managed properties. We have found no solution to do so. Did you figured out something like this? Best regards. Mario

December 16, 2011 2:07 AM
 

CoreyRoth said:

@Mario I haven't tried it before.

January 5, 2012 3:59 PM
 

Petro said:

Hi Corey,

Love the work you have done over the years!

I just have a very basic question for you... were the 2 additional lines of code -

this.QueryNumber = QueryId.Query2;

this.FixedQuery = string.Format("Write>=\"{0}\"", DateTime.Today.AddDays(-7));

In addition to the existing QueryManager code?

i.e.

                   this.QueryNumber = QueryId.Query2;

                   this.FixedQuery = string.Format("Write>=\"{0}\"", DateTime.Today.AddDays(-7));

                   QueryManager queryManager = SharedQueryManager.GetInstance(this.Page).QueryManager;

                   queryManager.UserQuery = string.Format("{0}*", queryManager.UserQuery);

I'm just not sure how to get this working.. ideally I'd like to hard code the query string via the 'this.FixedQuery' property, so if you could shed some light on what I'm doing wrong that would be great!

Note: The hard coded query could be as simple as this.FixedQuery = "john smith'

Thanks!

November 7, 2012 12:00 AM
 

CoreyRoth said:

@Petro Thanks!  You can actually do it either way.   You can either set the QueryNumber and then use the FixedQuery property.  Or as an alternative you can get a reference to the QueryManager object and set the UserQuery property.  I hope that helps.

November 7, 2012 10:40 AM
 

SharePoint Core Results Web Part Changes « Tom Resing's SharePoint Blog said:

Pingback from  SharePoint Core Results Web Part Changes «  Tom Resing's SharePoint Blog

January 27, 2014 10:19 AM
 

Measuring the Success of Your SharePoint Implementation; Should Gates Return to Microsoft?; Save 10% on Bamboo Suites – Bamboo Solutions said:

Pingback from  Measuring the Success of Your SharePoint Implementation; Should Gates Return to Microsoft?; Save 10% on Bamboo Suites – Bamboo Solutions

June 6, 2016 3:16 AM

Leave a Comment

(required)  
(optional)
(required)  
Add

About CoreyRoth

Corey Roth is an independent SharePoint consultant specializing in ECM, Apps, and Search.
2015 dotnetmafia.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems