I have the following code that is saving the byte array of an uploaded DOCX file (attached) to the database and then pulling the information from the database and saving it to the response stream.
protected void linkButtonUpdateEventTemplate_Click(object sender, EventArgs e)
{
if (!fileUploadEventTemplateUpdate.HasFile)
{
SetError("You must select a new file to upload");
return;
}
Var_EventTemplate eventTemplate = VarManager.GetEventTemplate(_eventTemplateID);
eventTemplate.FileContents = fileUploadEventTemplateUpdate.FileBytes;
SessionManager.DataBaseConnection.SaveChanges();
SetSuccess("Template updated");
}
protected void linkButtonDownloadEventTemplate_Click(object sender, EventArgs e)
{
Var_EventTemplate eventTemplate = VarManager.GetEventTemplate(_eventTemplateID);
using(MemoryStream ms = new MemoryStream(eventTemplate.FileContents))
{
Document doc = new Document(ms, new LoadOptions()
{
LoadFormat = LoadFormat.Docx
});
doc.Save(Response,
String.Format("{0}.docx", eventTemplate.Name),
ContentDisposition.Attachment,
new DocSaveOptions(SaveFormat.Docx));
}
}
When I call “doc.Save” with the information above, I receive the following error:
System.ArgumentException: An invalid SaveFormat for this options type was chosen.
Why? and how do I correct the issue?