Click here to Skip to main content
15,895,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When click on browse button of async file Upload Control i got the following error
Server Response Error: 'Unknown Server Error'
Do You want to see the response page?
Whats root cause ?Here is my Code

C#
protected void fileUploadComplete(object sender, AsyncFileUploadEventArgs e)
   {
       if (fileUpload1.HasFile && IsValidPhoto(Convert.ToInt32(fileUpload1.PostedFile.ContentLength)))//Checks Valid Photo Type or not
       {
           Thread.Sleep(1000);
           string newfilenameWithExt = "";
           string ext = System.IO.Path.GetExtension(fileUpload1.FileName);
           Bitmap bmpImg = null;
           newfilenameWithExt = hdnFileNmWithoutExt.Value + ext;//hidden field value is set on Page load
           if (hdnOldFileName.Value != "")//Old Picture is removed
           {
               string oldFilePath = Server.MapPath("~/") + "/storedata/" + "studentphotos/" + hdnOldFileName.Value;
               FileInfo oldFile = new FileInfo(oldFilePath);
               if (System.IO.File.Exists(oldFilePath))
                   System.IO.File.Delete(oldFilePath);
           }

           // Resize Image Before Uploading to Storedata
           bmpImg = Resize_Image(fileUpload1.PostedFile.InputStream, 97, 120);
           bmpImg.Save(Server.MapPath("~/") + "/storedata/" + "studentphotos/" + newfilenameWithExt, ImageFormat.Jpeg);

           Session["ProfileImg"] = newfilenameWithExt;

           loadStudentProfilePicture();//method to load studentprofilepicture
           HttpResponse.RemoveOutputCacheItem("/personalDetails.aspx");
           StudentApplication objStdFileUpload = new StudentApplication();
           objStdFileUpload.StudentFormID = 0;

           if (Session["FormId"] != DBNull.Value && Session["FormId"].ToString() != "")
               objStdFileUpload.StudentFormID = Convert.ToInt32(Session["FormId"].ToString());
           objStdFileUpload.StudentProfileImage = newfilenameWithExt;

           if (objStdFileUpload.StudentFormID != 0)
               objStdFileUpload.UpdateFileNameUploadByFormID();
       }
   }
Posted
Updated 7-Jan-15 22:42pm
v4

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900