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

  • SEARCH
  • Home
  • 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 6758633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:49:18+00:00 2026-05-26T13:49:18+00:00

I want to show icon that associated with file type. Something like this But

  • 0

I want to show icon that associated with file type. Something like this
enter image description here

But background is black (in firefox and IE), in chrome it is transparent, and its good.
enter image description here

My controller

 public ActionResult GetFileTypeIcon(string fileName)
        {
            var photo = PhotoModel.GetFileTypeIcon(fileName);

            if (photo == null)
            {
                return File(Url.Content("~/Content/Images/nofile.png"), "image/png");
            }

            var stream = new MemoryStream(photo);


            return File(stream.ToArray(), "image/bmp");
        }

I also try to convert icon to png but than quality of image is very bad.

var stream = new MemoryStream(photo);

            var iconStream = new MemoryStream();

            Image.FromStream(stream).Save(iconStream, System.Drawing.Imaging.ImageFormat.Png);

            return File(stream.ToArray(), "image/png");

enter image description here

view (i use devexpress grid)

@Html.DevExpress().GridView(settings =>
{
    settings.Name = "attachmentsGrid";

    settings.Columns.Add(col =>
    {
        col.Caption = "Назва";

        col.SetDataItemTemplateContent(c =>
        {
            ViewContext.Writer.Write("<table><tr><td>");

            //Html.DevExpress().BinaryImage(imageSettings =>
            //{
            //    imageSettings.Width = 16;
            //    imageSettings.Height = 16;
            //}).Bind(PhotoModel.GetFileTypeIcon(DataBinder.Eval(c.DataItem, "_name").ToString())).Render();
            ViewContext.Writer.Write("<img height=\"16px\" width=\"16px\" src=\"" + Url.Action("GetFileTypeIcon", "Photo", new { fileName = DataBinder.Eval(c.DataItem, "_name").ToString() }) + "\" alt=\"image\" />");
            ViewContext.Writer.Write("</td><td>");
            ViewContext.Writer.Write("&nbsp&nbsp");
            ViewContext.Writer.Write(
                 Html.ActionLink(DataBinder.Eval(c.DataItem, "_name").ToString(), "Download", new { Link = DataBinder.Eval(c.DataItem, "_link"), Name = DataBinder.Eval(c.DataItem, "_name") }));
            ViewContext.Writer.Write("</td></tr></table>");
        });
    });

and method thats return image as byte array. RegisteredFileType.ExtractIconFromFile – returns an Icon.

public static byte[] GetFileTypeIcon(string filename)
        {
            try
            {
                byte[] array;
                var fileType = filename.Split('.').LastOrDefault();
                fileType = "." + fileType.ToLower();
                string fileAndParam = (_iconsInfo[fileType]).ToString();

                if (String.IsNullOrEmpty(fileAndParam))
                    return null;

                var icon = RegisteredFileType.ExtractIconFromFile(fileAndParam, false);

                using (var ms = new MemoryStream())
                {
                    icon.ToBitmap().Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
                    array = ms.ToArray();
                }

                return array;
            }
            catch (Exception)
            {
                return null;
            }

i am change methhod GetFileTypeInfo: now it returns Icon

 var icon = RegisteredFileType.ExtractIconFromFile(fileAndParam, false);
                return icon;

And controller

public ActionResult GetFileTypeIcon(string fileName)
        {
            var photo = PhotoModel.GetFileTypeIcon(fileName);

            if (photo == null)
            {
                return File(Url.Content("~/Content/Images/nofile.png"), "image/png");
            }

            var stream = new MemoryStream();
            photo.ToBitmap().Save(stream, System.Drawing.Imaging.ImageFormat.Png);


            var iconStream = new MemoryStream();

            Image.FromStream(stream).Save(iconStream, System.Drawing.Imaging.ImageFormat.Bmp);

            return File(stream.ToArray(), "image/png");
        }

Now its render good in chrome , firefox, safari and opera, but in die IE IE its not.

  • 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-05-26T13:49:19+00:00Added an answer on May 26, 2026 at 1:49 pm

    It seems like image bolder issue. can you try to add img { border: 0; } to your site.css file to see if it helps?

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

Sidebar

Related Questions

On my program icon i want to show how many show a number, like
I want to show a border type look for an element but without using
How to show image icon of tabbar in full size like in this image
I want to show an icon in the actionbar providing the signal strength of
I have an appwidget and I want to show other installed applications' launcher icon
I want to show a different icon/image depending on an enum value. For example,
I want to show a icon (up or down) when i sort a column
Hi does anyone know I can display the icon of a file that has
I am new to android widget.I did sample application , that want to show
I want to show skype/msn/yahoo icons that show the online status in my ASP.NET

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.