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; } } }
private LoadDocumentEntity LoadDocument(string guid, string password) { LoadDocumentEntity loadDocumentEntity = new LoadDocumentEntity(); loadDocumentEntity.SetGuid(guid); ILoadOptions loadOptions = GetLoadOptions(guid); if (loadOptions != null) { loadOptions.Password = password; } // Instantiate Editor object by loading the input file using (GroupDocs.Editor.Editor editor = new GroupDocs.Editor.Editor(guid, delegate { return(loadOptions); })) { IDocumentInfo documentInfo = editor.GetDocumentInfo(password); dynamic editOptions = GetEditOptions(guid); if (editOptions is WordProcessingEditOptions) { editOptions.EnablePagination = true; // Open input document for edit — obtain an intermediate document, that can be edited EditableDocument beforeEdit = editor.Edit(editOptions); string allEmbeddedInsideString = beforeEdit.GetEmbeddedHtml(); PageDescriptionEntity page = new PageDescriptionEntity(); page.SetData(allEmbeddedInsideString); loadDocumentEntity.SetPages(page); beforeEdit.Dispose(); } else if (editOptions is SpreadsheetEditOptions) { for (var i = 0; i < documentInfo.PageCount; i++) { // Let's create an intermediate EditableDocument from the i tab SpreadsheetEditOptions sheetEditOptions = new SpreadsheetEditOptions(); sheetEditOptions.WorksheetIndex = i; // index is 0-based EditableDocument tabBeforeEdit = editor.Edit(sheetEditOptions); // Get document as a single base64-encoded string, where all resources (images, fonts, etc) // are embedded inside this string along with main textual content string allEmbeddedInsideString = tabBeforeEdit.GetEmbeddedHtml(); PageDescriptionEntity page = new PageDescriptionEntity(); page.SetData(allEmbeddedInsideString); page.number = i + 1; loadDocumentEntity.SetPages(page); tabBeforeEdit.Dispose(); } } else if (editOptions is PresentationEditOptions) { for (var i = 0; i < documentInfo.PageCount; i++) { // Create editing options PresentationEditOptions presentationEditOptions = new PresentationEditOptions(); // Specify slide index from original document. editOptions.SlideNumber = i; // Because index is 0-based, it is 1st slide EditableDocument slideBeforeEdit = editor.Edit(presentationEditOptions); // Get document as a single base64-encoded string, where all resources (images, fonts, etc) // are embedded inside this string along with main textual content string allEmbeddedInsideString = slideBeforeEdit.GetEmbeddedHtml(); PageDescriptionEntity page = new PageDescriptionEntity(); page.SetData(allEmbeddedInsideString); page.number = i + 1; loadDocumentEntity.SetPages(page); slideBeforeEdit.Dispose(); } } } return(loadDocumentEntity); }