FileUpload error that isn't actually erroring ???

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jason Kibble
    New Member
    • Jun 2011
    • 4

    FileUpload error that isn't actually erroring ???

    I have multiple FileUpload controls on the same page (about 30). I have a try...catch around the SaveAs Method for each of these controls. If an exception is caught, it adds the exception to a List<Exception> and after attempting to save all uploads, if the Exception List has any items, I get an email.

    I have been getting emails for many days now saying that Access was denied; however, when I check on the file, it was actually uploaded just fine. As a matter of fact, I have never checked on a file that was not uploaded successfully.

    Does anyone know why I might be getting these exceptions even though the SaveAs method seems to be working? Below is an excerpt of my code:

    Code:
    if (Day_Photo_1.HasFile)
    {
        //save file
        try
        {
            Day_Photo_1.SaveAs(savePath + "\\Day_Photo_1_" + Day_Photo_1.FileName.ToString());
            result = 0;
        }
        catch (Exception e)
        {
            Errors.Add(e);
            result = 1;
        }
    }
    else
    {
        result = 1;
    }
    
    ...
    
    if (Errors.Count > 0)
    {
        string body = "";
    
        body += "Below is a list of exceptions experienced during the 'UploadImages' routine:<br />";
    
        foreach (Exception ex in Errors)
        {
            body += "<br /><br />Exception: " + ex.Message;
        }
    
        System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
        msg.To.Add("me@somesite.com");
        msg.From = new System.Net.Mail.MailAddress("noreply@somesite.com");
        msg.Subject = "A file upload on the form has failed";
        msg.Body = body;
        msg.IsBodyHtml = true;
    
        System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.somesite.com");
        client.Send(msg);
    
    }
Working...