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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:21:16+00:00 2026-05-24T05:21:16+00:00

In my c# application, when i upload a file , it needs to be

  • 0

In my c# application, when i upload a file , it needs to be converted to temp file and store in a temporary folder then read the temp file as image find its height width every thing and later stores in databse.I am getting error when I read the temp file as image, as Out of Memory, below is my entire code.

string img = System.Windows.Forms.Application.StartupPath +@"\"+ path;
//in path .png file is accessed.
            string filename = Path.GetFileName(img);
            string internetCache = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache);
            string IEPath=internetCache+@"\tmp";
            if (!Directory.Exists(IEPath))
                Directory.CreateDirectory(IEPath);


            FileInfo fi = new FileInfo(img);
            FileStream fs = fi.OpenRead();
            //lResult = URLDownloadToFile(0, img.src, TempFolder & strFileName, 0, 0)
            Stream stream = fs;
            byte[] buffer = new byte[fs.Length];
            stream.Seek(273, SeekOrigin.Begin);
            stream.Read(buffer, 0, (int)buffer.Length);

            string tempfile = Path.Combine(IEPath, Math.Abs(filename.GetHashCode()) + ".tmp");
            File.WriteAllBytes(tempfile, buffer);
            fs.Close();
            stream.Close();

            string _contentType = "application/octet-stream";
            FileType Type = FileType.png;
            string MimeType = "image/png";
            FileStream fst = new FileStream(tempfile, FileMode.Open);
            Image _image = System.Drawing.Image.FromStream(fst, true, true);

The last line where I am getting the exception as out of memory.
Please help me to find a solution.

  • 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-24T05:21:19+00:00Added an answer on May 24, 2026 at 5:21 am

    I just followed the instructions of the question:

    1. read some file
    2. Copy the file to a temp file
    3. Read as image
    4. Get width & height

      var bytes = File.ReadAllBytes(@"C:\temp\duck.jpg");
      var temp = Path.GetTempFileName();
      File.WriteAllBytes(temp, bytes);
      
      var img = Image.FromFile(temp);
      Console.WriteLine ("width: {0}, height: {0}", img.Width, img.Height);
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web application that needs to take a file upload from the
If XHR2 is supported with file-upload capabilites, my application needs to do different preparation.
I'm writing GWT application where I need to upload video file and encode that
Inside a grails application, I need to upload a file under web-app/js, add a
I'm developing a file upload with JSF. The application saves three dates about the
I was volunteered to write a application that will take a mp3 file, upload
I'm trying to upload a file to SharePoint programmatically via a Mac Application that
I have a ASP.NET web application that allows end users to upload a file.
I have a java web application which needs to upload files and we want
I started working on a web application. This application needs lot of image handling.

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.