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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:52:35+00:00 2026-05-10T19:52:35+00:00

Basically I am inserting an image using the listviews inserting event, trying to resize

  • 0

Basically I am inserting an image using the listviews inserting event, trying to resize an image from the fileupload control, and then save it in a SQL database using LINQ.

I found some code to create a new bitmap of the content in the fileupload control, but this was to store it in a file on the server, from this source, but I need to save the bitmap back into the SQL database, which I think I need to convert back into a byte[] format.

So how do I convert the bitmap to a byte[] format?

If I am going about this the wrong way I would be grateful it you could correct me.

Here is my code:

            // Find the fileUpload control             string filename = uplImage.FileName;              // Create a bitmap in memory of the content of the fileUpload control             Bitmap originalBMP = new Bitmap(uplImage.FileContent);              // Calculate the new image dimensions             int origWidth = originalBMP.Width;             int origHeight = originalBMP.Height;             int sngRatio = origWidth / origHeight;             int newWidth = 100;             int newHeight = sngRatio * newWidth;              // Create a new bitmap which will hold the previous resized bitmap             Bitmap newBMP = new Bitmap(originalBMP, newWidth, newHeight);              // Create a graphic based on the new bitmap             Graphics oGraphics = Graphics.FromImage(newBMP);              // Set the properties for the new graphic file             oGraphics.SmoothingMode = SmoothingMode.AntiAlias;             oGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;              // Draw the new graphic based on the resized bitmap             oGraphics.DrawImage(originalBMP, 0, 0, newWidth, newHeight);                PHJamesDataContext db = new PHJamesDataContext();              System.IO.MemoryStream stream = new System.IO.MemoryStream();             newBMP.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);             stream.Position = 0;             byte[] data = new byte[stream.Length];              PHJProjectPhoto myPhoto =                 new PHJProjectPhoto                 {                     ProjectPhoto = data,                     OrderDate = DateTime.Now,                     ProjectPhotoCaption = ProjectPhotoCaptionTextBox.Text,                     ProjectId = selectedProjectId                 };              db.PHJProjectPhotos.InsertOnSubmit(myPhoto);             db.SubmitChanges(); 
  • 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. 2026-05-10T19:52:35+00:00Added an answer on May 10, 2026 at 7:52 pm

    You should be able to change this block to

            System.IO.MemoryStream stream = new System.IO.MemoryStream();         newBMP.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);          PHJProjectPhoto myPhoto =             new PHJProjectPhoto             {                 ProjectPhoto = stream.ToArray(), // <<--- This will convert your stream to a byte[]                 OrderDate = DateTime.Now,                 ProjectPhotoCaption = ProjectPhotoCaptionTextBox.Text,                 ProjectId = selectedProjectId             }; 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 99k
  • Answers 100k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The simplest solution is to add a "Reset" method to… May 11, 2026 at 7:50 pm
  • Editorial Team
    Editorial Team added an answer Visual Studio is configured to show whitespace. Press Ctrl+R, Ctrl+W.… May 11, 2026 at 7:50 pm
  • Editorial Team
    Editorial Team added an answer In your code behind, it looks like in your FindControls… May 11, 2026 at 7:50 pm

Related Questions

I am writing an application that logs status updates (GPS locations) from devices to
I am attempting to insert a mass of records into SQL Server 2005 from
currently, I am looking deeper into testing techniques, even though I am not sure
I'm writing an application where the user will create an appointment, and instantly get

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.