public void Execute(Model Model, Main View) { if (Document.HasUnsavedChanges) { Document.Save(Settings.GlobalSettings.BackupOnSave); } Succeeded = true; }
public void Execute(Model Model, Main View) { if (!Document.HasUnsavedChanges) { Document.OpenEditors.Remove(Editor); if (Document.OpenEditors.Count == 0 && !AppClosing) { Model.CloseDocument(Document); } Cancel = false; } else { // More than one open editor for this document - go ahead and close it. if (Document.OpenEditors.Count > 1) { Document.OpenEditors.Remove(Editor); Cancel = false; } else { var prompt = System.Windows.Forms.MessageBox.Show( String.Format("Save changes to {0}?", Document.GetTitle()), "Unsaved changes!", System.Windows.Forms.MessageBoxButtons.YesNoCancel); if (prompt == System.Windows.Forms.DialogResult.Yes) { Document.Save(Settings.GlobalSettings.BackupOnSave); if (!AppClosing) { Model.CloseDocument(Document); } Cancel = false; } else if (prompt == System.Windows.Forms.DialogResult.No) { if (!AppClosing) { Model.CloseDocument(Document); } Cancel = false; } else if (prompt == System.Windows.Forms.DialogResult.Cancel) { Cancel = true; } else { throw new InvalidProgramException(); } } } Succeeded = !Cancel; }
protected void butDownloadHTML_Click(object sender, EventArgs e) { if (fileupload.HasFile) { try { string myDate = DateTime.Now.ToString("MM-dd-yyyy--H-mm-ss--"); string filename = Path.GetFileName(fileupload.FileName); string fullpath = Server.MapPath("/Uploaded/") + myDate + filename; string fullpathExportDocX = fullpath.Replace(".docx", "-GroupDocsExport.docx"); string fullpathExportEmbeddedHTML = fullpath.Replace(".docx", "-GroupDocsExportEmbedded.html"); string fullpathExportHTML = fullpath.Replace(".docx", "-GroupDocsExport.html"); string fullpathExportPDF = fullpath.Replace(".docx", "-GroupDocsExport.pdf"); fullpathExportDocX = fullpathExportDocX.Replace("Uploaded", "Exported"); fullpathExportHTML = fullpathExportHTML.Replace("Uploaded", "Exported"); fullpathExportPDF = fullpathExportPDF.Replace("Uploaded", "Exported"); fullpathExportEmbeddedHTML = fullpathExportEmbeddedHTML.Replace("Uploaded", "Exported"); fileupload.SaveAs(fullpath); using (Editor editor = new Editor(fullpath)) { WordProcessingEditOptions editOptions = new WordProcessingEditOptions(); editOptions.EnablePagination = false; EditableDocument readyToSave = editor.Edit(editOptions); if (!string.IsNullOrEmpty(fullpathExportDocX)) { editor.Save(readyToSave, fullpathExportDocX, new WordProcessingSaveOptions(WordProcessingFormats.Docx)); } if (!string.IsNullOrEmpty(fullpathExportPDF)) { editor.Save(readyToSave, fullpathExportPDF, new PdfSaveOptions()); } if (!string.IsNullOrEmpty(fullpathExportHTML)) { readyToSave.Save(fullpathExportHTML); } if (!string.IsNullOrEmpty(fullpathExportEmbeddedHTML)) { var html = readyToSave.GetEmbeddedHtml(); File.WriteAllText(fullpathExportEmbeddedHTML, html); } readyToSave.Dispose(); editor.Dispose(); } lblStatus.Text = "Upload status: File uploaded and converted!"; } catch (Exception ex) { lblStatus.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message; } } }