We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to download a document rather than saving to specified location?

i want to send the save file into as a response then i want to download.

please provide the suggestion how to i download the file which is saved by using doc.save()

thank you

Hi there,

Thanks for your inquiry. Please use following code example to send output document to client browser. Hope this helps you.

<pre style=“background-color: rgb(255, 255, 255); font-family: “Courier New”; font-size: 9pt;”>/
* Called from the web-app index page (because the POST method is chosen for the input form).
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
// Get the output format selected by the user.
String formatType = “DOCX”;

// Open the stream. Read only access is enough for Aspose.Words to load a document.
InputStream stream = new FileInputStream(MyDir + “in.docx”);

// Load the entire document into memory.
com.aspose.words.Document doc = new com.aspose.words.Document(stream);

// You can close the stream now, it is no longer needed because the document is in memory.

// Once we have a document, we can save it to a file, stream or send to the client’s browser.
// We just send the document to the browser in this case.
sendToBrowser(doc, “Aspose Words”, formatType, true, response);
catch (Exception e)
throw new RuntimeException(e);

* Sends the document to the client’s browser.
private void sendToBrowser(Document doc, String demoName, String formatType, boolean openNewWindow, HttpServletResponse response)
throws Exception
String extension = formatType;

String fileName = " + demoName + “.” + extension + ";
// Add the Response header
response.setHeader(“content-disposition”,“attachment; filename=” + fileName);
response.addHeader(“content-disposition”,“inline; filename=” + fileName);

doc.save(response.getOutputStream(), SaveFormat.DOCX);