protected void NextButton2_Click(object sender, EventArgs e) { // Needs a file if (!UploadImageControl.HasFile) { StaticMethods.UpdateStatus("Please upload a file.", false, statusLabel); return; } // Needs the correct file type if (UploadImageControl.PostedFile.ContentType != "image/jpeg") { StaticMethods.UpdateStatus("File type of uploaded file is incorrect.", false, statusLabel); return; } Directory.CreateDirectory(MapPath("/Uploads/" + Session["UserID"])); string destDir = MapPath("/Uploads/" + Session["UserID"]); string savePath = destDir + @"\" + UploadImageControl.FileName; try { UploadImageControl.SaveAs(savePath); } catch (Exception ex) { StaticMethods.UpdateStatus("Failed to upload : " + savePath + " : " + ex.ToString(), false, statusLabel); return; } StaticMethods.UpdateStatus("Thanks " + Session["UserID"] + " - Successfully uploaded (" + new FileInfo(savePath).Name + ") to : " + @"\Uploads\" + Session["UserID"], true, statusLabel); LastFileUploaded.Value = new FileInfo(savePath).Name; MultiViewControl.ActiveViewIndex++; }
private void _Event_UploadImageButton_Clicked(object sender, RoutedEventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Files | *.jpg; *.jpeg; *.png;"; dialog.FilterIndex = 1; if (dialog.ShowDialog() == true) { var control = new UploadImageControl(new MessageUploadFileModel() { ConversationID = Model.Key, FileName = System.IO.Path.GetFileName(dialog.FileName), FilePath = dialog.FileName, }); MessageImagesContainer.Children.Add(control); } }