Note that there are some explanatory texts on larger screens.

plurals
  1. POEfficiently Map Extension string to Icon URL
    primarykey
    data
    text
    <p>I have an ASP.NET web application hosted on a CMS(sharepoint 2013) that has built in search.</p> <p>When running a file query with search, the only indication of the file type is an extension string, formatted without a period <code>"PNG" or "JPG"</code></p> <p>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.</p> <p>I looked around the site for a question like this, and I don't see one.</p> <p>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:</p> <p>FINAL RESULT:</p> <pre><code>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&lt;String, String&gt; IconUrls = new Dictionary&lt;String,String&gt;() { {"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]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload