File handling in c#
<p>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.</p>

<pre><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 &amp; 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);
</code></pre>

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