We help IT Professionals succeed at work.

Avoid the "Convert File" pop up box when opening a dynamically created word document from asp code


I have code that will dynamically create a word document from the asp code below.  I want to avoid the pop up "convert file" box when trying to open the document dynamically created.  Any suggestions?

 <!--#include file="../includes/connection.asp"-->
sql = "select * from owner where ownerID = 1"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sql, objConn

file_being_created= "AAtest_" & rs("ownerid") & ".doc"
set fso = createobject("scripting.filesystemobject")
Set act = fso.CreateTextFile(server.MapPath(file_being_created), true)
act.WriteLine("<tr><td>State:</td><td> " & rs("ownerID") & "</td></tr>" )
act.WriteLine("<tr><td>Owner:</td><td> " & rs("owner") & "</td></tr>")
act.WriteLine("<tr><td colspan=2>Page created on: " & now ()&"</td></tr>")

Watch Question

b0lsc0ttIT Manager


I haven't actually had to work with this exact issue but I have some ideas.  First, add the lines below to your script ...

Response.Write "The code page is " & Session.Codepage

Let me know what you get from that line.  Also, I believe you are describing the "box" that appears when you open that file that asks you to select the encoding to use; A "file conversion" box.  Is that correct?  Do you know what encoding you want to use for the file and characters?  What selection in that conversion box does Word default to?

The simplest fix is to try ...

Set act = fso.CreateTextFile(server.MapPath(file_being_created), true, true)

That should have the object use unicode and may be enough for Word to auto detect it.  Word will open basic text files without that prompt but something in the document (characters or the encoding of the file) is making it want to confirm.

Let me know what you find out and how this works.  Let me know if you have any questions or need more information.



Hi b0lsc0tt,

Okay when I run the code to display the Session.Codepage .......I get 1252

Yes, I believe it is a file conversion box.  

I don't know what encoding I want to use for the file and characters.... I select "HTML Document"

FYI - I have done this so that the finished product is formated and therefor legible.


Forgot to mention in the previous post, I did add the extra "true" in the Set act = fso.CreateTextFile(server.MapPath(file_being_created), true, true) statement like you suggested but that did not make any difference.

Hopefully you can still help.

b0lsc0ttIT Manager

Thanks for the replies and info.

What version of Word?  How are you opening the file?

What happens if you give it the .txt extension instead of .doc?




The version of word is XP.

I am presently writing to a text file but it will not format and writing to word was my solution to making sure the text is legiible/formated.

b0lsc0ttIT Manager

I tested your code with my server and used Word 2007 to open the file.  I did not get the message.  What was the result if you used the .txt extension instead?  Of course you will probably loose that "formatting" but it is probably the cause of this.  What happens if you just make text and use the .doc extension?

The latest version of Word does have better "html" support than earlier ones.  However do you have to get rid of that message or support Word XP?  Do you have the option to make a rtf file?  If not, what type of formatting do you need for the text file?  The content may need to be changed to make it more Word friendly.

Let me know if you have a question about this.  Thanks for the info you provided in the reply.




I guess I wish I was using Word 2007 but that is not an option.  We are using Word XP and will probably not be updating for quite some time.  

When I changed it from .doc to .txt:  I get a text file with the html tags for the table

When I changed it from .doc to .rtf:  I still get the convert file pop up box.

The document being dynamically created is a quote for a client and therefor needs to formatted with a table or something of the sorts.  

Any other suggestions?  Maybe I should look into writing to a pdf document but from what I understand that costs $$$.

IT Manager
The maybe some free pdf components you could have the server use but security and quality are sometimes an issue with those.  If you aren't on your own server (i.e. on a hosted server) then you may not even be able to add a component to do this.  Of course if you are on a hosted server then check with the host to see if they already have something that will work.

Another option would be an rtf file.  I don't know enough about the format to tell you how to make it but it is a text file and not proprietary.  I found an article on MS' site that is real close to what you need.  Look at http://support.microsoft.com/kb/270906 .  The key would be learning how to make the text in a rich text format.  Personally I feel MS Word will handle rtf files better, especially over different Word versions, than PDF or html files/content.

Let me know if you have a question or how this helps.

Forced accept.

EE Admin

Explore More ContentExplore courses, solutions, and other research materials related to this topic.