Link to home
Start Free TrialLog in
Avatar of spiritedSmile
spiritedSmile

asked on

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

Hi,

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("<table>")
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>")
act.WriteLine("</table>")
act.close
response.Redirect("http://www.google.ca")
%>



Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

spiritedSmile,

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
Response.End

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.

b0lsc0tt
Avatar of spiritedSmile
spiritedSmile

ASKER

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.

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?

bol
Hi,

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.

 
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.

bol
Hi,

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 $$$.

ASKER CERTIFIED SOLUTION
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Forced accept.

Computer101
EE Admin