Free Support Forum - aspose.com

Neither SaveType method works

I am trying to open a Word doc, but neither the OpenInWord nor OpenInBrowser are working correctly. There are two issues: one is with read-only, the other has to do with SaveType:

Issue #1:

  • I save the document using doc.Save(myDocName) [doc is an instantiation of Document]. That works.
  • I added doc.Protect(ProtectionType.NoProtection) before doc.Save, since the docs were opening in Read-Only mode. That didn’t change anything; they still opened as Read-Only. I need to open them so they can be edited and saved.

Issue #2:
  • If I try to open the doc for editing using: doc.Save(myDocName, SaveFormat.Doc, SaveType.OpenInWord, Response), I get square brackets appended to the file name, e.g. “lab_result_238239[1].doc”, which seems to be an IE issue (based on other forums and other threads in this forum), as it does not occur with Firefox. Unfortunately, IE is the company standard, so that’s what I’m stuck with. So the OpenInWord option is out.
  • If I try to open the doc for editing using doc.Save(myDocName, SaveFormat.Doc, SaveType.OpenInBrowser, Response), the file name is now listed as “GetDoc.aspx” in the Word title bar (GetDoc.aspx is the .NET web form name), and when attempting to save, the doc name that displays is “GetDoc.doc”. In another thread (http://www.aspose.com/Community/Forums/thread/40969/why-name-the-document-when-saving-to-browser.aspx), the response was that "the passed filename indeed seems to be ignored. That appears to be standard browser behavior and we have nothing to do with it."

So, given that SaveType only has those two options and neither work, what am I supposed to do?

(I’m running XP, Word 2003, and IE7).

Thanks

Hi

Thanks for your interest in Aspose.Words.

1. Could you please attach your documents for testing (input and output)? Also please provide me code example that will allow me to reproduce this problem

2. I don’t think that this is Aspose.Words bug. This save method works like the following code.

MemoryStream stream = new MemoryStream();

doc.Save(stream, SaveFormat.Doc);

Response.Clear();

//Specify the document type.

Response.ContentType = "application/msword";

//Other options:

//Response.ContentType = "text/plain"

//Response.ContentType = "text/html"

//Specify how the document is sent to the browser.

//Response.AddHeader("content-disposition","attachment; filename=MyDocument.doc");

//Another option could be:

Response.AddHeader("content-disposition", "inline; filename=MyDocument.doc");

//Get data bytes from the stream and send it to the response.

byte[] bytes = stream.GetBuffer();

Response.BinaryWrite(bytes);

Response.End();

Best regards.

Alexey,

I’ve attached a stripped down solution in a zip file. I’ve been testing it both using the built-in web server in VS2005 (for basic debugging) and on my own IIS (for a more realistic scenario). Near the bottom (lines 123-131) of the GetDoc.aspx.cs file is where the attempt is made to open the doc. I have tried four different ways of doing this, and each has its own issues (the first two are the Aspose methods which I referenced in my original post).

When you say the save method works like the code above, are you suggesting I try using that code in place of the Save method I’m curently using?

Thanks!

Alexey,

I tried your code; I replaced my try-catch block with the code you supplied above (for some reason, VS2005 threw an exception when I put your code in a try-catch block - but commenting out the try-catch made that problem go away).

I got the same result as when I use the OpenInWord method: brackets appended to the end of the file name (IE bug, I know. But not much help when that’s the company standard).

Thanks

To clarify my last post:

When using Alexey’s code, specifically Response.AddHeader(“content-disposition”,“attachment; filename=MyDocument.doc”) line, the result is the same as using the OpenInWord method (brackets added to file name).

When using: Response.AddHeader(“content-disposition”, “inline; filename=MyDocument.doc”), the result is the same as using the OpenInBrowser method (filename shown as GetDoc.doc).

Hi

1. I didn’t manage to reproduce your issue with read-only. Document is opened in editable mode on my side.

2. Yes, you are absolutely right. SaveType.OpenInWords use “attachment” and SaveType.OpenInBrowser use “inline”. I was not quite correct. This method works same way as code I provided.

Best regards.

I think I can get around the read-only issue by using a macro that saves the doc in another location. So the remaining issue is with the file name.

Hi

Unfortunately, I can’t provide you any solution regarding this issue.

Best regards.

Alexey,

Were you able to reproduce the issue, and there’s not a solution? Or were you not able to reproduce the issue? Just curious if there’s anymore information I can provide.

Thanks

Hi

I can reproduce this issue on my side. But I can’t provide you solution because this problem isn’t related with Aspose.Words. This is bug of browser.

Best regards.

OK. Thanks for looking into it.