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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:13:13+00:00 2026-06-05T05:13:13+00:00

I am having a really weird issue with my image saving method. First, here

  • 0

I am having a really weird issue with my image saving method. First, here is the method:

        public static void uploadImageToServer(string savePath, HttpPostedFile imageToUpload, bool overwrite)
        {
                byte[] myData = new Byte[imageToUpload.ContentLength];
                imageToUpload.InputStream.Read(myData, 0, imageToUpload.ContentLength);

                FileStream newFile = new FileStream(savePath, FileMode.Create);
                newFile.Write(myData, 0, myData.Length);
                newFile.Close();
}

As you can see from the input parameters this method works in conjuction with the FileUpload control. Now I am using this method from two pages which both have a FileUpload control. On one page the image uploads file, on the other page it results in a corrupted file.

I am really at a loss as to why the image is being corrupted. I am using the same image, the same method, and the same input control.

Is there any way I can debug this?

  • 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-05T05:13:15+00:00Added an answer on June 5, 2026 at 5:13 am

    Gonna steal alexn’s answer <_<

    You are over-complicating it. Just use the built-in FileUpload::SaveAs(save_path) that is provided for you.

    You can use the Server.MapPath() method to help you get a dynamic path to your root directory, go from there and append the file name to it.
    Not sure why you are getting that error. My best guess is either your savePath is broken (or the filename/extension appended to it), or the bytes are not being read/written to perfectly.. Anyway, you should not get that error by using the method I described (considering you don’t mess up the file extension :).

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

Sidebar

Related Questions

I'm having a really weird issue with a background worker in one of my
This is a really weird issue I'm having and I'm not really sure what
I'm currently having a really weird issue and I can't seem to figure out
I am having a weird problem here, and I am really stuck, need to
I am having this really weird issue with downloading files from within ASP.Net MVC
I am having a really weird issue with IIS on one of our servers.
I'm having an issue with the Singleton pattern. It is really weird, but it
I'm having a really weird issue with some content that is being inserted with
I am having a weird problem here, and I am really stuck, need to
I'm having a really weird problem with my rails app and facebook's open graph

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.