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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:11:37+00:00 2026-05-27T23:11:37+00:00

I have an ASP Image control that I want to save to a specific

  • 0

I have an ASP Image control that I want to save to a specific folder.

Image1.ImageUrl = "~/fa/barcode.aspx?d=" + Label1.Text.ToUpper();

This is basically what barcode.aspx does:

 Bitmap oBitmap = new Bitmap(w, 100);

        // then create a Graphic object for the bitmap we just created.
        Graphics oGraphics = Graphics.FromImage(oBitmap);

        oGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
        oGraphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;


        // Let's create the Point and Brushes for the barcode
        PointF oPoint = new PointF(2f, 2f);
        SolidBrush oBrushWrite = new SolidBrush(Color.Black);
        SolidBrush oBrush = new SolidBrush(Color.White);

        // Now lets create the actual barcode image
        // with a rectangle filled with white color
        oGraphics.FillRectangle(oBrush, 0, 0, w, 100);

        // We have to put prefix and sufix of an asterisk (*),
        // in order to be a valid barcode
        oGraphics.DrawString("*" + Code + "*", oFont, oBrushWrite, oPoint);
Response.ContentType = "image/jpeg";
oBitmap.Save(Response.OutputStream, ImageFormat.Jpeg);

How do I save it to a folder (~/fa/barcodeimages/)? So far here’s what I tried:

WebClient webClient = new WebClient();
                string remote = "http://" + Request.Url.Authority.ToString() + "/fa/barcode.aspx?d=" + Label1.Text.ToUpper();
                string local = Server.MapPath("barcodeimages/" + Label1.Text.ToUpper() + ".jpeg");
                webClient.DownloadFile(remote, local);

But it does not work, I always get a corrupted .jpeg file. And it seems inefficient.

  • 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-27T23:11:38+00:00Added an answer on May 27, 2026 at 11:11 pm

    It looks like the problem is that your business logic – the code required to generate a barcode image – is in the wrong place.

    You should keep that business logic away from the presentation logic of your aspx page (which is about serving an image to respond to a URL), and move the Bitmap creation logic to somewhere that both the “serve a barcode” and “save a barcode to disk” code can get at it. That could be in a different business logic assembly, or it could simply be in a separate class within the same project. The main thing is that you want it in a reusable place.

    At that point, your aspx code changes to something like:

    Response.ContentType = "image/jpeg";
    using (Bitmap bitmap = barcodeGenerator.Generate(Code))
    {
        bitmap.Save(Response.OutputStream, ImageFormat.Jpeg);
    }
    

    and your saving code changes to something like:

    // TODO: Validate that the text here doesn't contain dots, slashes etc
    string code = Label1.Text.ToUpper();
    string file = Server.MapPath("barcodeimages/" + code + ".jpeg");
    using (Bitmap bitmap = barcodeGenerator.Generate(code))
    {
        bitmap.Save(file, ImageFormat.Jpeg);
    }
    

    Here, barcodeGenerator would ideally be a depedency-injected instance of your BarcodeGenerator class (or whatever it turns out to be). If you’re not using dependency injection, you could create a new instance directly, specifying the font etc each time – it’s not as pleasant, but it should work okay.

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

Sidebar

Related Questions

I have a asp image control. ImageUrl=images/avator.jpg. I'm changing this picture on the server
I have an Image control on my .aspx page and I want to set
I have a FileUpload Control and a image control on asp.net page as follows
I am attaching an asp.net textbox image I want my textbox should have two
I want to display image in img control. Asp code: <asp:Image id=id src='<%# Eval(Item.SmallPicPath)
I have a GridView control in an Asp.net application, that has a <asp:buttonField> of
I've got an asp:Image. I want this control to display, only if <%#Eval(Image)%> is
I have Image in ItemTemplate that will be changing according to Username (ie lblPostedBy.Text).
I have a custom asp.net server control to display images.What I need now is
I have a custom Asp.net control as public class ImageControl : Panel { private

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.