- Home
- Forum
- JavaScript - EJ 2
- Export functionality
Export functionality
Created server side functionality using file formats library, using code described in export section of the document editor.
WordDocument document = WordDocument.Load(stream, GetFormatType(type.ToLower()));
string sfdt = Newtonsoft.Json.JsonConvert.SerializeObject(document);
document.Dispose();
return sdft;causes
Environment : ASP.NET MVC
.NET Framework 4.5
Tried numerous word documents. There are lot's of suggestions on how to avoid this from Google search but none of them helped.
Some of them crashed IIS server (oops)
Love to hear your take on it.
Thanks
SIGN IN To post a reply.
3 Replies
RT
Ramya Thirugnanam
Syncfusion Team
March 1, 2019 10:15 AM UTC
Hi Sampurnima,
Thanks for contacting Syncfusion support.
We were unable to reproduce the reported issue "Self-referencing loop detected for property 'Document'" from our side. And the code example which you have provided is related to import operation. So, from this we suspect you are trying to implement Import functionality for document editor. For your convenience, we have prepared an MVC Web API sample with Import and Export operation. Please find the sample from below link.
Sample link: http://www.syncfusion.com/downloads/support/directtrac/143030/ze/DocumentEditor-1594165561
If the same issue reproduced in this sample. kindly provide us an input document to replicate this issue. So that we will investigate on this and provide you appropriate solution at the earliest.
Note: If you have any confidential data in your Word document, please replace with some dummy data and provide us the same. We just need your document to recreate the problem you face.
Regards,
Ramya T
SK
sk
March 3, 2019 03:58 AM UTC
Now I have different issues exporting PDF file.
I am creating blob and try to POST the form to the server
server does not receive any files
Here is the client side code
var form = document.createElement("form");
form.setAttribute('method',"post");
form.setAttribute('encType',"multipart/form-data");
form.setAttribute('action',"http://localhost:64927/convert.aspx");
var outputFileName = document.createElement("input");
outputFileName.type = "hidden";
outputFileName.name = "outputFileName";
outputFileName.value = "filename.pdf";
form.appendChild(outputFileName);
var outputFormat = document.createElement("input");
outputFormat.type = "hidden";
outputFormat.name = "outputFormat";
outputFormat.value = "pdf";
form.appendChild(outputFormat);
// save the document as blob
var exportedDocument = documentEditor.saveAsBlob('Docx');
//create a form and using existing fields
var formData = new FormData(form);
// send the file name
formData.append('fileName', 'sample.docx');
/ // send the blob
formData.append('data', exportedDocument);
fetch(form.action, {
method: form.method,
body: formData
}).then(function(res) {
if (!res.ok) {
console.log('something unexpected happened')
}
res.text().then(function(text) {
console.log(text);
})
})
------------------- server side code ----
I am using asp.net mvc
public partial class _convert : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
AddOnPreRenderCompleteAsync(
new BeginEventHandler(BeginAsyncOperation),
new EndEventHandler(EndAsyncOperation)
);
}
IAsyncResult BeginAsyncOperation(object sender, EventArgs e,
AsyncCallback cb, object state)
{
Func convert = ConvertData;
var asyncState = new AsyncState(convert, state);
return convert.BeginInvoke(cb, asyncState);
}
void EndAsyncOperation(IAsyncResult ar)
{
var asyncState = (AsyncState)ar.AsyncState;
var del = (Func)asyncState.Del;
var rc = del.EndInvoke(ar);
Response.Write(rc);
}
public string ConvertData()
{
// THIS IS WHERE IT FAILS, always return 0 file count
if (Request.Files.Count <= 0)
{
errorString = "[{\"successful\":false,\"errorCode\":-14}]";
return (errorString);
}
HttpPostedFile postedFile = Request.Files[0];
string file_name = postedFile.FileName;
if (string.IsNullOrEmpty(file_name))
{
errorString = "[{\"successful\":false,\"errorCode\":-15}]";
return (errorString);
}
if (postedFile.ContentLength <= 0)
{
errorString = "[{\"successful\":false,\"errorCode\":-16}]";
return (errorString);
}
.......
}
it always says, the file count is zero. Spend whole day, totally stumped
Am I missing something?
Thanks
RT
Ramya Thirugnanam
Syncfusion Team
March 5, 2019 05:16 AM UTC
Hi Sampurnima,
Thanks for contacting Syncfusion support.
The reported issue occurs due to the wrong usage of 'saveAsBlob' method. This method returns a 'Promise' object but in your client-side code you are trying to access the Promise object as blob. So, due to this only this issue occurs. So, please modify the client-side code as below to resolve this issue.
|
var form = document.createElement("form");
form.setAttribute('method', "post");
form.setAttribute('encType', "multipart/form-data");
var outputFileName = document.createElement("input");
outputFileName.type = "hidden";
outputFileName.name = "outputFileName";
outputFileName.value = "filename.pdf";
form.appendChild(outputFileName);
var outputFormat = document.createElement("input");
outputFormat.type = "hidden";
outputFormat.name = "outputFormat";
outputFormat.value = "pdf";
form.appendChild(outputFormat);
// save the document as blob
documentEditor.saveAsBlob('Docx').then(function (exportedDocument) {
//create a form and using existing fields
var formData = new FormData(form);
// send the file name
formData.append('fileName', 'sample.docx');
// send the blob
formData.append('data', exportedDocument);
fetch(form.action, {
method: form.method,
body: formData
}).then(function (res) {
if (!res.ok) {
console.log('something unexpected happened')
}
res.text().then(function (text) {
console.log(text);
})
})
}); |
Regards,
Ramya T
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
SK sk
- Mar 1, 2019 06:16 AM UTC
- Mar 5, 2019 05:16 AM UTC