string virtualDir = "/Global/UserPetImages";
UnifiedDirectory directory = UnifiedDirectory.CreateDirectory(virtualDir);
string fileNamePattern = "User555_PetImage*";
UnifiedSearchQuery query = new UnifiedSearchQuery();query.FileNamePattern = fileNamePattern;
UnifiedSearchHitCollection searchResult = directory.Search(query);
I get an error on the last line. I get
[NullReferenceException: Object reference not set to an instance of an object.] Lucene.Net.QueryParsers.QueryParser.Escape(String s) +78 EPiServer.Web.Hosting.Versioning.Store.LuceneQuery.Search(UnifiedSearchQuery userQuery) +144 EPiServer.Web.Hosting.VersioningDirectory.Search(UnifiedSearchQuery query) +118 Masterpet.Web.Templates.Masterpet.Controls.PetDetails.UploadPetImageFile(Int32 userId, String& filename) in D:\SVN\Karuba\Masterpet\masterpet.com\trunk\Site\Templates\Masterpet\Controls\PetDetails.ascx.cs:224 Masterpet.Web.Templates.Masterpet.Controls.PetDetails.Update(Int32 userId) in D:\SVN\Karuba\Masterpet\masterpet.com\trunk\Site\Templates\Masterpet\Controls\PetDetails.ascx.cs:142 Masterpet.Web.Templates.Masterpet.Pages.ProfilePetPage.UpdatePets_OnClick(Object sender, EventArgs e) in D:\SVN\Karuba\Masterpet\masterpet.com\trunk\Site\Templates\Masterpet\Pages\ProfilePetPage.aspx.cs:76 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
directory is not null and query is not null. My guess is it has something to do with initializing the UnifiedSearchQuery?
Got it! I needed to add this:
query.FreeTextQuery = "";
For some reason, I'm not getting the correct results anymore. It was working before.
Am I doing the search correctly?
Object reference not set to an instance of an object.