Uploading photo ( because it is being used by another process. )?
<p>When I upload the image it is showing this error please can u help me?</p>

<p>The process cannot access the file 'C:\Websites\telugufilmchance\httpdocs\User\photo\thumb\PPTS00025sonali.jpeg' because it is being used by another process. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. </p>

<p>Exception Details: System.IO.IOException: The process cannot access the file 'C:\Websites\telugufilmchance\httpdocs\User\photo\thumb\PPTS00025sonali.jpeg' because it is being used by another process.</p>

<p>Source Error: </p>

<pre><code>if (ext == ".JPEG" || ext == ".JPG" || ext == ".PNG" || ext == ".BMP" || ext == ".GIF")
Line 193:            {
Line 194:                fupPhoto.PostedFile.SaveAs(path + filename);
Line 195:                Bitmap src = Bitmap.FromStream(fupPhoto.PostedFile.InputStream) as Bitmap;
Line 196:                Bitmap result = ResizeBitmap(src);
</code></pre>

<p>this is my code (updating code it is a edit page and i am updating)</p>

<pre><code>  if (fupPhoto.FileName != string.Empty)
        {
            filename = ran(fupPhoto.FileName);
            FileInfo fi = new FileInfo(filename);
            string ext = fi.Extension.ToUpper();
            string path = Server.MapPath("../User/photo/thumb/");              
            if (ext == ".JPEG" || ext == ".JPG" || ext == ".PNG" || ext == ".BMP" || ext == ".GIF")
            {
                fupPhoto.PostedFile.SaveAs(path + filename);
                Bitmap src = Bitmap.FromStream(fupPhoto.PostedFile.InputStream) as Bitmap;
                Bitmap result = ResizeBitmap(src);
                SizeMgt(filename);
                System.Drawing.Bitmap img = new System.Drawing.Bitmap(result, newwid, newhgt);
                System.Drawing.Imaging.ImageCodecInfo jpegcodec = null;
                System.Drawing.Imaging.EncoderParameters EncParams;
                foreach (System.Drawing.Imaging.ImageCodecInfo codec in System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders())
                {
                    if (codec.MimeType == "image/jpeg")
                    {
                        jpegcodec = codec;
                        break;
                    }
                }

                EncParams = new System.Drawing.Imaging.EncoderParameters(1);
                EncParams.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 20L);
                newfilename = "new" + filename;
                img.Save(path + newfilename, jpegcodec, EncParams);
                img.Dispose();

            }
        }
        else
        {
            newfilename = myphot; 
        }

                cmd = new SqlCommand("sp_uptreg", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@tregno", lblregno1.Text);
                cmd.Parameters.AddWithValue("@catid", ddlCategory.SelectedItem.Value);

                cmd.Parameters.AddWithValue("@fname", txtfname.Text);
                cmd.Parameters.AddWithValue("@mname", txtmname.Text);
                cmd.Parameters.AddWithValue("@lname", txtlname.Text);

                cmd.Parameters.AddWithValue("@emailid", txtEmail.Text);
                cmd.Parameters.AddWithValue("@phoneno", txtphone.Text);
                cmd.Parameters.AddWithValue("@mobileno", txtMobile.Text);
                cmd.Parameters.AddWithValue("@address", txtAdd.Text);

                cmd.Parameters.AddWithValue("@photos", newfilename);


                    int a = cmd.ExecuteNonQuery();
</code></pre>
