View Single Post
  #3 (permalink)  
Old April 12th, 2012, 04:55 PM
malie22001 malie22001 is offline
Authorized User
Points: 194, Level: 3
Points: 194, Level: 3 Points: 194, Level: 3 Points: 194, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2011
Posts: 41
Thanks: 0
Thanked 1 Time in 1 Post
Default

Exactly; that is what I am trying to do, but it sems all the code that I have written to test te size are being ignored. I have even set a break point in the code, but as long as the size of the file is above 4MB, my code is skipped and te browser displays an error. I don't get to my custom error message. Here is the code I have written within the ItemInserting event handler of the DetailsView control:

Code:
protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e) 
    { 
        //try 
        //{ 
        FileUpload imageUpload = (FileUpload)DetailsView1.FindControl("FileUpload1"); 
 
        if (imageUpload.HasFile) 
        { 
            int fileSize = imageUpload.PostedFile.ContentLength; 
 
            if (fileSize < 2000000) 
            { 
                string virtualFolder = "~/ServiceImages/"; 
                string physicalFolder = Server.MapPath(virtualFolder); 
                string filename = Guid.NewGuid().ToString(); 
                string extension = Path.GetExtension(imageUpload.FileName); 
 
                imageUpload.SaveAs(Path.Combine(physicalFolder, filename + extension)); 
 
                e.Values["ServiceID"] = Convert.ToInt32(DropDownList1.SelectedItem.Value); 
                e.Values["DateAdded"] = DateTime.Now; 
                e.Values["ImageUrl"] = virtualFolder + filename + extension; 
            } 
            else 
            { 
                erroLabel.Text = "File size too huge."; 
                erroLabel.Visible = true; 
            } 
        } 
        else 
        { 
            erroLabel.Text = "You have not selected a file."; 
        } 
 
         
 
         
        //} 
        //catch (SqlException ex) 
        //{ 
 
        //} 
        //catch (Exception ex) 
        //{ 
 
        //} 
 
 
    }
Please advice.

Thank you.

Last edited by malie22001; April 12th, 2012 at 04:56 PM.. Reason: error
Reply With Quote