Hello I am trying to view the word/excel/ppt document in Groupdocs editor using asp.net mvc(web api, jQuery, JavaScript) like how it is working →
Word Editor, Excel Editor, PowerPoint Editor
Below is my code for the same,
my cshtml Page →
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>CreateOfficeFiles</title>
</head>
<body>
<div>
<textarea name="htmlContent" style="width:100%; height:500px;">@Html.Raw(ViewBag.HtmlContent)</textarea>
</div>
</body>
</html>
my controller
public async Task<ActionResult> CreateOfficeFiles(string queryString)
{
Utils.AES256 aes = new Utils.AES256();
var queryData = aes.DecryptQueryStringAsObject(queryString);
var fileuploadPath = System.IO.Path.Combine(Program.GetTempFolderPath(), "FileUpload");
string fullFilePath = queryData.FilePath;
if (string.IsNullOrEmpty(queryData.FilePath))
{
var guid = Convert.ToString(Guid.NewGuid());
if (queryData.EditorType == "docx")
{
fullFilePath = fileuploadPath + "\\" + guid + ".docx";
await CreateEmptyWordFile(fullFilePath);
}
else if (queryData.EditorType == "xlsx")
{
fullFilePath = fileuploadPath + "\\" + guid + ".xlsx";
await CreateEmptyExcelFile(fullFilePath);
}
else if (queryData.EditorType == "pptx")
{
fullFilePath = fileuploadPath + "\\" + guid + ".pptx";
await CreateEmptyPPTFile(fullFilePath);
}
}
SPResponse sp = await LoadWordFile(fullFilePath);
ViewBag.HtmlContent = sp.Ref1.ToString();
return View();
}
CreateEmptyWordFile
, CreateEmptyExcelFile
, CreateEmptyPPTFile
is an API call to my Groupdocs application which is helping me to create empty word/excel/ppt files if queryData.FilePath
is empty.
here is my code for the same →
[HttpPost]
[Route("api/GroupDocsApi/CreateEmptyWordFile")]
public async Task<SPResponse> CreateEmptyWordFile(DocPro.DMS.BusinessEntities.Request.GroupDocs.GetDocumentInfoRequest request)
{
try
{
Document document = new Document();
await Task.Run(() => document.Save(request.FileUploadPath));
return new SPResponse() { ReturnStatus = "0" };
}
catch (Exception ex)
{
return new SPResponse() { ReturnStatus = "-1", ReturnMessage = ex.Message };
}
}
[HttpPost]
[Route("api/GroupDocsApi/CreateEmptyExcelFile")]
public async Task<SPResponse> CreateEmptyExcelFile(DocPro.DMS.BusinessEntities.Request.GroupDocs.GetDocumentInfoRequest request)
{
try
{
Workbook workbook = new Workbook();
await Task.Run(() => workbook.Save(request.FileUploadPath));
return new SPResponse() { ReturnStatus = "0" };
}
catch (Exception ex)
{
return new SPResponse() { ReturnStatus = "-1", ReturnMessage = ex.Message };
}
}
[HttpPost]
[Route("api/GroupDocsApi/CreateEmptyPPTFile")]
public async Task<SPResponse> CreateEmptyPPTFile(DocPro.DMS.BusinessEntities.Request.GroupDocs.GetDocumentInfoRequest request)
{
try
{
Presentation presentation = new Presentation();
await Task.Run(() => presentation.Save(request.FileUploadPath, Aspose.Slides.Export.SaveFormat.Pptx));
return new SPResponse() { ReturnStatus = "0" };
}
catch (Exception ex)
{
return new SPResponse() { ReturnStatus = "-1", ReturnMessage = ex.Message };
}
}
after this my new API is getting executed LoadWordFile
in that API I’m loading the document, below is the code →
[HttpPost]
[Route("api/GroupDocsApi/LoadWordFile")]
public async Task<SPResponse> LoadWordFile(DocPro.DMS.BusinessEntities.Request.GroupDocs.GetDocumentInfoRequest request)
{
try
{
SPResponse sp = new SPResponse() { ReturnStatus = "-1" };
await Task.Run(() =>
{
using (FileStream fs = new FileStream(request.FileUploadPath, FileMode.Open, FileAccess.Read))
{
Editor editor = new Editor(() => fs);
WordProcessingEditOptions editOptions = new WordProcessingEditOptions();
EditableDocument document = editor.Edit(editOptions);
sp.Ref1 = document.GetContent();
sp.ReturnStatus = "0";
}
});
return sp;
}
catch (Exception ex)
{
return new SPResponse() { ReturnStatus = "-1", ReturnMessage = ex.Message };
}
}
but this is how the editor is showing the data →
Editor (54.4 KB)
I want to view this as it is working in online example but I am not able to find any example for that.
I had tried only docx file but I want to do this for ppt as well as for excel files too.
thank you in advance