Document name with spaces and special characters

I’m using aspose.words to generate a word document and send to the client. Everything works fine except the name of the document that the client gets. To save and send it I use this method:

doc.Save(name, SaveFormat.Doc, SaveType.OpenInWord, page.Response);

If the name of the document is “Finalización de los trabajos.doc” I only get “Finalizaci%c3%b3n” with Firefox and “Finalización_de_los_trabajos.doc” with IE 7.

Is there something I can do to solve it?

Hi

Thanks for your inquiry. There is no one way to resolve the problem, since different browsers handle file names differently. Regarding IE and FireFox, you can try using the following code to resolve the problem:

string name = "this is file name with white spaces.doc";
switch (Request.Browser.Browser)
{
    case "Firefox":
        doc.Save("\"" + name + "\"", SaveFormat.Doc, SaveType.OpenInBrowser, Response);
        break;
    case "IE":
        doc.Save(HttpUtility.UrlPathEncode(name), SaveFormat.Doc, SaveType.OpenInBrowser, Response);
        break;
    default:
        doc.Save(name, SaveFormat.Doc, SaveType.OpenInBrowser, Response);
        break;
}
Response.End();

Hope this helps.
Best regards.

It works great with the spaces, but the problem (in Firefox) with the special characters like accents (example: ó) still remains.

Hi

Thanks for your request. However, the problem you mentioned is not related to Aspose.Words. I think, this is some kind of bug in FireFox.
The Save method works like the following code.

Aspose.Words.Document doc = new Aspose.Words.Document();
Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
builder.Write("Hello world!!!");
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();

As you see, Aspose.Words does nothing with file name. File name is changed on client side by browser. So you should contact with FireFox support to resolve the issue with special characters.
Best regards.

Thanks for the answer, at least I have solved the problem with the spaces. The strange thing is that I use some similar code in other part of the proyect and it works great in Firefox.

Response.AddHeader("Content-Disposition", "attachment;filename="" + filename + """);

Do you know the different of use “inline” vs “attachment”?

Hi

Thanks for your inquiry. When you use “attachment” the document will be opened in new window (this is SaveType.OpenInWord), when you use “inline” the document will be opened in browser window (SaveType.OpenInBrowser option).
Best regards.