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 8574183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:25:02+00:00 2026-06-11T19:25:02+00:00

I have several ASP.NET MVC3 and 4 web sites. All sites are using the

  • 0

I have several ASP.NET MVC3 and 4 web sites. All sites are using the same resources that are separate to a library. Resources are .resx files.
I’d like to use images from these resource in my html inside these sites.
I wasn’t using resx files before so not sure what is a good way to work with them.
I think that I might create a service to provide right image from right resource file, but i guess there should be a better way.
My question is what is a good way to use these images from resx files and might be it is not really good to store images in a resx?

  • 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-11T19:25:03+00:00Added an answer on June 11, 2026 at 7:25 pm

    One easy way to do this is to add a FileStreamResult action to the controller, which should return the image based on the resource key.

    public FileStreamResult Image(string key)
    {
        var bitmap = (Bitmap)Resources.Images.ResourceManager.GetObject(key);
        MemoryStream stream = new MemoryStream();
        bitmap.Save(stream, ImageFormat.Png);
        stream.Seek(0, SeekOrigin.Begin);
        return new FileStreamResult(stream, "image/png");
    }
    

    Now you should be able to access it from your view like this:

    <img src='@Url.Action("Image", "MyController", new { key = "Image1" })' />
    

    An alternate way (which can be done using only the view) is to create a base 64 encoded string.

    @{
        var stream = new MemoryStream();
        var bitmap = Resources.Images.ResourceManager.GetObject("Image1") as System.Drawing.Bitmap;
        bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
        stream.Seek(0, SeekOrigin.Begin);
        string base64 = Convert.ToBase64String(stream.ToArray());
    }
    
    <img src="data:image/gif;base64,@base64" />
    

    A good way to implement this might be to use a Razor helper, to enable the more straightforward syntax in the view @Html.GetImageFor(Resources.Images.Image1, "alt").

    public static MvcHtmlString GetImageFor(this HtmlHelper helper, Bitmap bitmap, string AltText = "")
    {
        MemoryStream stream = new MemoryStream();
        bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
        stream.Seek(0, SeekOrigin.Begin);
        string base64 = Convert.ToBase64String(stream.ToArray());
    
        return new MvcHtmlString(
            string.Format("<img src='data:image/gif;base64,{0}' alt='{1}' />",
                base64, AltText)
        );
    }
    


    Note: The properties on the .ResX files should be set as follows (as normal for MVC projects):

    • set CustomTool to PublicResXFileCodeGenerator
    • set Custom Tool Namespace to Resources
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several ASP.NET MVC 3 Web applications that have a lot of common
I have several sites (Asp.Net) that I would like to have a single sign
I have several RequiredFieldValidators in an ASP.NET 1.1 web application that are firing on
We manage several ASP.NET MVC client web sites, which all use a data annotation
I have several ASP.NET sites in IIS7 and would like to be able to
I have several performance issue in my website. I'm using asp.net mvc 2 and
A simple question. I have an ASP.NET web application which contains several assemblies and
I have an asp.net mvc3 project, it has some reports in aspx web pages.
Background: I'm writing ASP.NET MVC 3 Web app. I have a List<MyObject> (actually several
I have an ASP.NET web site that has a entities version 4.0 DAL. I

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.