DocumentSave Method (HttpResponse, String, ContentDisposition, SaveOptions)

Sends the document to the client browser.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.2
Syntax
public SaveOutputParameters Save(
	HttpResponse response,
	string fileName,
	ContentDisposition contentDisposition,
	SaveOptions saveOptions
)

Parameters

response
Type: System.WebHttpResponse
Response object where to save the document.
fileName
Type: SystemString
The name for the document that will appear at the client browser. The name should not contain path.
contentDisposition
Type: Aspose.WordsContentDisposition
A ContentDisposition value that specifies how the document is presented at the client browser.
saveOptions
Type: Aspose.Words.SavingSaveOptions
Specifies the options that control how the document is saved. Can be null.

Return Value

Type: SaveOutputParameters
Additional information that you can optionally use.
Remarks

Internally, this method saves to a memory stream first and then copies to the response stream because the response stream does not support seek.

Examples
Performs a simple insertion of data into merge fields and sends the document to the browser inline.
// Open an existing document
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertField(" MERGEFIELD FullName ");
builder.InsertParagraph();
builder.InsertField(" MERGEFIELD Company ");
builder.InsertParagraph();
builder.InsertField(" MERGEFIELD Address ");
builder.InsertParagraph();
builder.InsertField(" MERGEFIELD City ");

// Fill the fields in the document with user data
doc.MailMerge.Execute(new string[] { "FullName", "Company", "Address", "City" },
    new object[] { "James Bond", "MI5 Headquarters", "Milbank", "London" });

// Send the document in Word format to the client browser with an option to save to disk or open inside the current browser
Assert.That(() => doc.Save(response, "Artifacts/MailMerge.ExecuteArray.doc", ContentDisposition.Inline, null), 
    Throws.TypeOf<ArgumentNullException>()); //Thrown because HttpResponse is null in the test.

// The response will need to be closed manually to make sure that no superfluous content is added to the document after saving
Assert.That(() => response.End(), Throws.TypeOf<NullReferenceException>());
See Also