private void Upload(Object Source, EventArgs e) { if (myFile.PostedFile != null) { int intFileLength; string ImgFileNamePath; string ImgFileName; if (myFile.PostedFile.ContentType != "image/pjpeg") { lbResult.Text = "Tipo di file non valido"; } else { if (myFile.PostedFile.ContentLength > 2000000) { lbResult.Text = "File troppo grande"; } else { try { ImgFileNamePath = myFile.PostedFile.FileName; intFileLength = ImgFileNamePath.Length-ImgFileNamePath.LastIndexOf("\\"); ImgFileName = ImgFileNamePath.Substring(ImgFileNamePath.Length-intFileLength+1); myFile.PostedFile.SaveAs(Server.MapPath("image/annunci/small/") + ImgFileName); lbResult.Text = "File salvato"; } catch (Exception ex) { lbResult.Text = @"Errore nel salvataggio:" + ex.Message; } } } } } //in your form