Free Support Forum - aspose.com

Returning multiple documents from ASP.NET application

Hi-

I have an applicaiton where I am reading multiple documents stored on a web server (under App_Data directory), replacing their bookmarks with data from the database and returning them to the user. Unfortunately only 1 document is being returned into the Response stream whereas I would like for all the documents to be returnd to the user so that the user can either save them or open them in MS Word for viewing. Here is the code that I am using:

private void GenerateDocuments(IEnumerable endorsements,
Dictionary submissionData) {
foreach (var endorsement in endorsements) {
string filePath = string.Empty;
filePath = Path.Combine(Server.MapPath(endorsement.DocumentPath),
endorsement.DocumentName);

Document doc = new Document(filePath);
foreach (Bookmark bookmark in doc.Range.Bookmarks) {
string key = bookmark.Name;
if (submissionData.ContainsKey(key)) {
bookmark.Text = (submissionData[key] == null) ? string.Empty :
submissionData[key].ToString();
}
}
doc.Save(endorsement.DocumentName, SaveFormat.Doc, SaveType.OpenInWord, Response);
}
}

Any idea how I can get this to work?

Thanks in advance,

Ali

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. You can send only one file through http Response. If you need to send multiple documents then you can try zipping them and send archive to user.

Best regards.

So if I understand this correctly. There is no way to stream back multiple documents in response to a single request? My best option is either to zip them up into a single archive or potentially merge them to form a single large document?

Is this a limitation of how Aspose.Words is built or some sort of an ASP.NET restriction? Are there any plans to improve this behavior?

Thanks.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request.

1. The easiest way is merging all documents together in one large document. You can do this using the following code for example:

Document dstDoc = new Document("doc1.doc");

Document srcDoc = new Document("doc2.doc");

foreach (Section srcSection in srcDoc.Sections)

{

Node dstSection = dstDoc.ImportNode(srcSection, true, Aspose.Words.ImportFormatMode.KeepSourceFormatting);

dstDoc.AppendChild(dstSection);

}

dstDoc.Save("out.doc");

2. No it is not limitation of Aspose.Words. This is limitation of HTTP protocol.

Best regards.