This worked fine, but after some time the customer reported a bug that it was not possible to get the SearchDataSource to return search hits in the documents they had uploaded. Hm...this worked fine some weeks ago, so I did a search on EPiServer World and found this thread: Cannot get SearchDataSource to return files. I tried all the tips in this post, but I only got the search to work in edit mode. After some hours debugging I found out that all files returned by SearchDataSource.PerformUnifiedFileSystemSearch() has PageVisibleInMenu set to false. So if you set EnableVisibleInMenu to true, no Docments will be displayed. The issue has been reported with EPiServer as #14072: Searchdatasource does not return any files if EnableVisibleInMenu is set to true.

A nice way to get this to work is to implement your own SearchDataSource that inherits from EPiServer.Web.WebControls.SearchDataSource and override CreateFileSearchMatch() like this:

using System;
using System.Web.UI;
using EPiServer.Core;
using EPiServer.Security;
using EPiServer.Web.WebControls;

namespace Templates.WebControls
{
[ParseChildren(ChildrenAsProperties = true), PersistChildren(false)]
public class CustomSearchDataSource : SearchDataSource
{
protected override PageData CreateFileSearchMatch(string fileName, string fileUrl, DateTime lastModified, int rank, string iconUrl)
{
PageData data = new PageData(PageReference.EmptyReference);
data.Property["PageName"] = new PropertyString(fileName);
data.Property["PageLinkURL"] = new PropertyString(fileUrl);
data.Property["PageChanged"] = new PropertyDate(lastModified);
data.Property["PagePendingPublish"] = new PropertyBoolean(false);
data.Property.Add("PageRank", new PropertyNumber(rank));
data.Property.Add("IconPath", new PropertyString(iconUrl));
data.Property["PageWorkStatus"] = new PropertyNumber(4);
data.Property["PageStartPublish"] = new PropertyDate(lastModified);
data.ACL.Add(new AccessControlEntry(EveryoneRole.RoleName, AccessLevel.FullAccess));
data.Property["PageVisibleInMenu"] = new PropertyBoolean(true);
return data;
}
}
}

The only thing that is added is this line of code: data.Property["PageVisibleInMenu"] = new PropertyBoolean(true);
Now all documents will have PageVisibleInMenu set to true!

In the aspx file, use this:

<%@ Register TagPrefix="uc" Namespace="Templates.WebControls" Assembly="AssenblyName" %>

<uc:CustomSearchDataSource ID="SearchDataSource" runat="server" EnableVisibleInMenu="true">
<SelectParameters>
<EPiServer:PropertyParameter Name="PageLink" PropertyName="SearchRoot" />
<asp:ControlParameter Name="SearchQuery" ControlID="SearchText" PropertyName="Text" />
<asp:ControlParameter Name="SearchFiles" ControlID="SearchInFiles" PropertyName="Checked" />
<asp:ControlParameter Name="OnlyWholeWords" ControlID="SearchOnlyWholeWords" PropertyName="Checked" />
</SelectParameters>
</ucCustomSearchDataSource>