Free Support Forum -

Help with redirecting after making a letter

my code

doc.Save(“AddYourFileNameHere.doc”, SaveFormat.FormatDocument, SaveType.OpenInWord, Me.Response)

The problem: Once I finish making/saving the letter though the dialog box that appears, I want to be able to redirect to another page. How can I do this? I tried to do me.response.redirect(“somePage.aspx”) but that didn’t work (syntax errors)

Any help is greatly appreciated. thanks in advance.


This is not really Aspose.Word question, it is a pure ASP.NET question. I don’t think we have enough experience of this sort in ASP.NET. Maybe other forums users can help. I would also advise you to look for the answer elsewhere on the internet in .NET forums.

Did you have any luck resolving this issue? We are evaluating the Word component of Aspose and need to do the same.


I have a similar problem and a partial solution. I need to display a status message page while the document is being prepared on the server and return to the request page (using a redirect) when the file has completed download.

Expanded description of the problem… When you use the “SaveType.OpenInWord” option, the Aspose component changes the Response.ContentType from “text/html” to “application/msword” and therefore the page is no longer rendered as a Web Page so any JavaScript is irrelevant at this point.

My work-around… I do not know if my solution is correct, but it works for me partially. My status message page is a standard HTML page with a 1 pixel X 1 pixel IFRAME. In the IFRAME, the document is prepared using the Aspose component. In the main message page there is a redirect in the document.onLoad() event. The document.onLoad() does not appear to fire until the Aspose component completes the processing and downloading of the document in the IFRAME. This causes the message page to be displayed while the Aspose component is processing and executes the redirect when complete, thus achieving the effect that I desire… with one exception.

The redirect works correctly if the user selects “Open” or “Cancel” option in the file download box, but the redirect never occurs if the user selects the “Save” option. I am still looking for a complete solution that will work for all download options.


Has anyone found a full solution to this problem? This is really causing an issue for us.

The reason you can't redirect is because sending MIME content to the browser takes up all of the response. There's no "context" to tell the browser to go to another page because the WHOLE response sent to the browser (including the ending) is the MIME content filled with the document.

Here's what I've done (only works on Window browser, Mac browser must do something else).

1. Create a HTTP handler for "download" requests:

2. Create the class/assembly referenced above. This class should implement IHttpHandler.

3. In the ProcessRequest method, simply set the MIME headers and send the document as a Response.

4. In the page that "Requested" downloadreport.aspx, javascript must be used:

a. When the user first presses the button to download, set "document.onreadystatechange = CheckForFinish;"
b. Do a "setTimeout('DoDownload()', 1000);"
c. Do a "document.location = 'downloadreport.aspx';"
d. The user should now start to download.

Here's the rest...

function CheckForFinish()
if (document.readyState == 'interactive' || document.readyState == 'complete')
{ = 'default';
setTimeout('Redirect()', 2000);

function Redirect()
document.location = 'newpage.aspx';

Hope this helps.


I do have a question regarding this step in your method…

3. In the ProcessRequest method, simply set the MIME headers and send the document as a Response.

I have my class created fine, I just can’t figure out how to set the MIME headers and send the document as Response in the ProcessRequest method.

Do you have a code sample? Thanks so much for your help

You can do it manually, or simply use the methods Apose.Word provides:

doc.Save(“AddYourFileNameHere.doc”, SaveFormat.FormatDocument, SaveType.OpenInWord, Response);

This works great when running a simple example.

I started to implement this into a more complex webform, where I have a session variable, and I get this error where it finds the session variable:

"Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive"

I have session state enabled in web.config and also on the page. Have you run into this anywhere?

No, I haven’t. My webform that performs launches the download and the form that generates the report are both pretty extensive and it works fine on both Mac and Windows.