Free Support Forum -

Document name

When I try saving a document that has spaces in the document name, it gets saved as a filename up to the first space.


Dim strFilename As String = String.Format("{0}.doc", Me.txtCourseName.Text)
doc.Save(strFilename, SaveFormat.Doc, SaveType.OpenInWord, Me.Response)

For example, strFileName = "This Is My File.doc"

What actually gets streamed out to the web user is "This.doc"

Is there any way to get the document to save correctly with the spacing?

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

I have simplified the test and tried this:

Sub Test1()

Dim doc As Document = New Document()

doc.Save("This Is My File.doc")

End Sub

The code saves "This Is My File.doc" as it is specified. Are you sure your string variable contains proper file name? There could be some special character we don’t see in debugger which gives such a behavior. Please provide more information to reproduce the issue. Also note that it is not related to Aspose.Words itself.


I already verified this works as well. The issue here is that the document is saved for downloading to a client, that is the reason it uses the overloaded save method.

doc.Save(strFilename, SaveFormat.Doc, SaveType.OpenInWord, Me.Response)

Prior to the overloaded Save method, you had to do this manually. One of the lines was:

Response.AddHeader(“content-disposition”, “attachment; filename=” & strFilename & “”)

I believe it’s the header response that is messing it up because it doesn’t like spaces.

When the document name is converted to a part of the URL spaces are not allowed. In URLs space characters should be escaped with special sequence: %20. Just try the same but substituting spaces in file name with this sequence. Browsers will recognize this and show the original name.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />


No go. Replacing the spaces with %20 takes them as literal text.

Meaning, the download is named: My%20Word%20Document.doc


I think that you can try using the following code to solve your problem.

string fileName = "out1 test.doc";

if (Request.Browser.Browser.ToString().ToUpper() == "IE" && Request.Browser.MajorVersion >= 7)

fileName = fileName.Replace(" ", "%20");

doc.Save("\"" + fileName + "\"", SaveFormat.Doc, SaveType.OpenInWord, Response);

I hope that this will help you.

Best regards.


This solved the issue, thanks so much. Works in all browsers too.

Thanks again.