World is now on Opti ID! Learn more
AI OnAI Off
World is now on Opti ID! Learn more
Anyone? The question is:
Is it possible to search part of filename using the file manager search?
You could implement a custom search provider, like this:
[Export(typeof(ISearchProvider))] public class CustomFileSearchProvider : ISearchProvider { private static ILog _log = LogManager.GetLogger(typeof(CustomFileSearchProvider)); public string Area { get { return "CMS"; } } public string Category { get { return "Filenames"; } } public IEnumerable<SearchResult> Search(Query query) { var list = new List<SearchResult>(); foreach (string virtualDir in (IEnumerable<string>)VirtualPathHandler.Instance.VirtualPathToNameMapping.Keys) { try { UnifiedDirectory unifiedDirectory = HostingEnvironment.VirtualPathProvider.GetDirectory(virtualDir) as UnifiedDirectory; if (unifiedDirectory != null) { var filez = unifiedDirectory.Files; var files = new List<UnifiedFile>(); GetAllFiles(unifiedDirectory, files); list.AddRange(from file in files where file.Name.Contains(query.SearchQuery) select CreateSearchResult(file.VirtualPath, file.Name)); } } catch (Exception ex) { _log.Warn((object)"There was an error when trying to perform a search for filenames.", ex); } } return list; } private void GetAllFiles(UnifiedDirectory start, List<UnifiedFile> files) { foreach (UnifiedFile file in start.GetFiles()) { files.Add(file); } foreach (UnifiedDirectory dir in start.GetDirectories()) { GetAllFiles(dir, files); } } private SearchResult CreateSearchResult(string path, string name) { return new SearchResult(UriSupport.ResolveUrlFromUIBySettings(string.Format("edit/default.aspx?plugin={0}&selectedfile={1}", (object)PlugInDescriptor.Load("EPiServer.UI.Hosting.VirtualPathControl", "EPiServer.UI").ID, (object)HttpUtility.UrlEncode(path))), name, null) { IconCssClass = this.GetIcon(name) }; } private string GetIcon(string fileName) { return "epi-resourceIcon epi-resourceIcon-" + Path.GetExtension(fileName).TrimStart(new char[1] { '.' }); } }
How can I configure Episerver to use my custom files search provider? Could you point me to any documentation on this?
Mark your class with a [SearchProvider] attribute, and make sure you have added a reference to System.Component.Composition.
More documentation can be found here:
http://world.episerver.com/Blogs/Magnus-Stalberg/Dates/2009/10/Implementing-a-Search-provider-for-SiteCenter-in-5-minutes/
http://world.episerver.com/Documentation/Items/Tech-Notes/EPiServer-CMS-6/EPiServer-CMS-60/OnlineCenter-Developer-Documentation/#AddingSearchProviders
When searching for files in the File Manager I can search for 'small*' and would find any file starting with 'small', eg 'smallcat.png'. If I need to find every file with the word 'cat' in its filename, however, I can't seem to find a way to do that. 'cat' returns 0 results and so does '*cat' and even '*cat*'.
How do one search for part of a filename?