I have an ASP.NET web application hosted on a CMS(sharepoint 2013) that has built in search.
When running a file query with search, the only indication of the file type is an extension string, formatted without a period "PNG" or "JPG"
I do not get a file back, I just get metadata describing the file. To be clear, I do not get any MIME types or file objects, I JUST get an extension string.
I looked around the site for a question like this, and I don’t see one.
It seems like there could be some sort of method that returns a string, and takes a string input in its signature, and searches through an object collection of some type, as follows:
FINAL RESULT:
static class FileIcons
{
static public string PDF = string.Format("{0}", SPContext.Current.Site.ServerRelativeUrl + "_layouts/15/monkeysphere/images/icons/pdf.png");
static public string Word = string.Format("{0}", SPContext.Current.Site.ServerRelativeUrl + "_layouts/15/monkeysphere/images/icons/word.png");
static public string Generic = string.Format("{0}", SPContext.Current.Site.ServerRelativeUrl + "_layouts/15/monkeysphere/images/icons/file.png");
static private Dictionary<String, String> IconUrls = new Dictionary<String,String>()
{
{"JPG", Picture},{"JPEG", Picture},{"GIF", Picture},{"PNG", Picture},
{"PDF", PDF},{"DOC", Word},{"DOCX", Word},{"XLS", Excel},{"XLSX", Excel},{"PPT", PowerPoint},{"PPTX", PowerPoint}
};
static public string GetIconUrlFromExtension(string extension)
{
var formattedExtension = extension.Trim().Replace(".","").ToUpper();
if (string.IsNullOrEmpty(extension) || !IconUrls.ContainsKey(formattedExtension))
return Generic;
return IconUrls[formattedExtension];
}
}
I think a
Dictionarywould be a better option. Something like this:You could also load the mappings from a configuration file so as not to hard code them.