Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8787153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:48:54+00:00 2026-06-13T21:48:54+00:00

I have an ASP.NET web application hosted on a CMS(sharepoint 2013) that has built

  • 0

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];
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:48:57+00:00Added an answer on June 13, 2026 at 9:48 pm

    I think a Dictionary would be a better option. Something like this:

    public static class IconUrls {
        static Dictionary<string, string> _extensions;
        static string DefaultUrl = "~/siteroot/images/icons/genericicon.png";
    
        static IconUrls {
            extensions = new Dictionary<string, string>() {
                { "JPG", "~/siteroot/images/icons/jpegicon.png" }, 
                { "JPEG", "~/siteroot/images/icons/jpegicon.png" }
            }
        }
    
        public static Dictionary<string, string> Extensions {
            get {
                return _extensions;
            }
        }
    
        public static string GetIconUrl(string extension) {
        {
            if(string.IsNullOrEmpty(extension) || !_dictionary.ContainsKey(extension.Trim().ToUpper()))
                return DefaultUrl;
            return _extensions[extension.Trim().ToUpper()];
        }
    }
    

    You could also load the mappings from a configuration file so as not to hard code them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an ASP.NET web application that we offer as a Service (it's hosted
i have a silverlight application that is hosted within a asp.net web application. in
I have an ASP.Net application that is hosted on my corporate clients web servers
We have an ASP.NET web application hosted by a web farm of many instances
I have a asp.net web application that uses C#. It logs in on a
I have a ASP.NET web application which has more than 100 pages. Each page
I have an ASP.NET web application that is using forms authentication. Everything is configured
I have an ASP.NET web application that, for whatever reason, when it is deployed
I have a ASP.NET Web Forms application that internally makes many SOAP and REST
I have an asp.net mvc 2 web application that connects to a WCF web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.