partial void FileUpload_Execute() { Dispatchers.Main.Invoke(() => { SelectFileWindow selectFileWindow = new SelectFileWindow(); selectFileWindow.Closed += SelectFileWindow_Closed; selectFileWindow.Show(); } ); }
partial void Import_Execute() { description = this.ShowInputBox("Bitte geben Sie eine Beschreibung ein.", "Neue Vorlage..."); Dispatchers.Main.BeginInvoke(() => { SelectFileWindow selectFileWindow = new SelectFileWindow() { Text = "Bitte geben Sie die Datei an, die Sie als neue Vorlage verwenden möchten.", Filter = "Worddokumente (*.docx)|*.docx|Alle Dateien (*.*)|*.*" }; selectFileWindow.Closed += new EventHandler(SelectFileWindow_Closed); selectFileWindow.Show(); }); }
private void SelectFileWindow_Closed(object sender, EventArgs e) { SelectFileWindow selectFileWindow = (SelectFileWindow)sender; string fileName = String.Empty; if (selectFileWindow.DialogResult == true && selectFileWindow.DocumentStream != null) { try { byte[] fileData = new byte[selectFileWindow.DocumentStream.Length]; using (StreamReader streamReader = new StreamReader(selectFileWindow.DocumentStream)) { for (int i = 0; i < selectFileWindow.DocumentStream.Length; i++) { fileData[i] = (byte)selectFileWindow.DocumentStream.ReadByte(); } } fileName = selectFileWindow.FileName; if (fileData != null) { this.StartWebApiCommand <FileUploadResponseParameters>("api/File/Upload", new FileUploadRequestParameters { BinaryData = fileData, FileName = fileName, ReferenceId = this.si_applications.SelectedItem.application_id, ReferencedEntitySet = "si_application_adv_details", RecordId = this.si_application_mediaCollection.SelectedItem.Id }, (error, responseParams) => { //IsBusy = false; //SelectedFileName = fileName; this.si_application_mediaCollection.Refresh(); if (error != null || responseParams.UploadStatus != "ok") { this.ShowMessageBox(error.ToString()); //"Something went wrong...\nUpload Failed..."); } // SelectedFileName = "Something went wrong..."; }); } } catch (IOException ex) { this.ShowMessageBox(ex.Message, "I/O Error", MessageBoxOption.Ok); } } }
private void SelectFileWindow_Closed(object sender, EventArgs e) { SelectFileWindow selectFileWindow = (SelectFileWindow)sender; byte[] bytes = null; if (selectFileWindow.DialogResult.GetValueOrDefault(false) && (selectFileWindow.DocumentStream != null)) { bytes = new byte[selectFileWindow.DocumentStream.Length]; using (StreamReader streamReader = new StreamReader(selectFileWindow.DocumentStream)) { for (int i = 0; i < selectFileWindow.DocumentStream.Length; i++) { bytes[i] = (byte)selectFileWindow.DocumentStream.ReadByte(); } } selectFileWindow.DocumentStream.Close(); selectFileWindow.DocumentStream.Dispose(); } if (bytes == null) { return; } string filename = selectFileWindow.SafeFileName; Details.Dispatcher.EnsureInvoke(() => { using (var dw = Application.Current.CreateDataWorkspace()) { var newItem = dw.ApplicationData.ReportingTemplatesSet.AddNew(); newItem.OriginalFilename = filename; newItem.ReleaseDate = DateTime.Now; newItem.Beschreibung = description ?? ""; newItem.Template = bytes; dw.ApplicationData.SaveChanges(); } Refresh(); }); }