Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Failed to save the ASP to word document.

Posted on 2005-04-14
21
Medium Priority
?
490 Views
Last Modified: 2012-06-22
I need to create a asp page which allows the user to click on the save image and then save the ASP page as a word document. See the below code.
It pops up the window and does save the file.
But when i open the doucment, it is empty. PLEASE help.. maybe security issue or word configuration...



==
<%@LANGUAGE="JSCRIPT" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
if (Request.QueryString=="save") {
    Response.Clear
      Response.Buffer = true
    Response.ContentType = "application/msword"
      Response.addHeader("content-disposition","attachment;filename=myfrom.doc");
}
%>
<%

var sMyString = "Who's work is this? - have single quote"
Response.Write("sMyString:" + sMyString)
Response.Write("<P>createTicket > " + createTicket(sMyString))

%>


<script language='JavaScript' runat='server'>
function createTicket(strUser )
{
  var objRegExp = new RegExp("'", "gi");
  var strReplaceText = "''";                    
     strUser =strUser.replace(objRegExp, strReplaceText);
       Response.Write("<P> after converted. strUser:" + strUser);
  return(strUser );
}
</script>

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<table width="100%"  border="1" bgcolor="#ECECEC">
    <th scope="col"><span class="style8">Performance Management System</span><BR>
      <span class="style9"><img src="Image/spacer.gif" width="1" height="1">Performance Appraisal Form</span>
       <a href="javascript:print()"><img src="Image/tool-print.gif" width="20" height="20" border="0"></a>
     <img src="Image/spacer.gif" width="10" height="1">
     <a href="<%=Request.ServerVariables("SCRIPT_NAME")%>?save"><img src="Image/save.jpeg" width="24" height="24" border="0"></a>
</table>
<body>

</body>
</html>
0
Comment
Question by:LeanMoreTryMore
  • 9
  • 6
  • 4
  • +1
21 Comments
 
LVL 3

Expert Comment

by:xiong8086
ID: 13787681
delete this statement 'Response.Buffer = true', and try again.

cheers.

xiong


0
 
LVL 11

Expert Comment

by:ajaikumarr
ID: 13787807
Hai,

I suspect that you can't add any text or images inside word document straight away using html tags on asp pages. Either you have to save the html as word file or ou have to use the word object to create the word document and then provide an option for download.

Bye
Ajai
0
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 13787884
Actually, regardless if it is plain text, HTML, RTF or real MSWord, if you save it as a .doc file Word will open it and when you attempt to  save it it will ask if you want to keep its format or convert it to .doc.

I've used that a lot.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:LeanMoreTryMore
ID: 13787888
Hi ajaikumarr,

it works before..after save one successfully,
and then, all of sudden it doesn't work.

Hi xiong,
I try as advised. but it stil got the same result.
0
 

Author Comment

by:LeanMoreTryMore
ID: 13787957
ok. my test page does work. Thanks for all. I can save the asp page as a word doc.

BUT when i add the following statments at the top of my page. When I click on the image file, it does display the window, but but it looks different compared to my test page.


My test page, it displays the window like below

Filename     myform.doc
File type      Microsoft word document
From          localhost


The above does make sense to me as what i sepecify

BUT in my actual ASP PAGE, WHEN i click on the image file.

Filename     ....viewHRAckForm_action.asp?save               ** it supposes to be myform.doc but it displays the URL name
File type                                                                        ** file name is NULL
From          localhost

SEE MY CODE BELOW. Anyone who can solve my mystery would be greatly appricated.

<%@LANGUAGE="JSCRIPT" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
if (Request.QueryString=="save") {
    Response.Clear
    Response.ContentType = "application/msword"
      Response.addHeader("content-disposition","attachment;filename=myfrom.doc");
}
%>


<table width="100%"  border="1" bgcolor="#ECECEC">
    <th scope="col"><span class="style8">Performance Management System</span><BR>
      <span class="style9"><img src="Image/spacer.gif" width="1" height="1">Performance Appraisal Form</span>
       <a href="javascript:print()"><img src="Image/tool-print.gif" width="20" height="20" border="0"></a>
     <img src="Image/spacer.gif" width="10" height="1">
     <a href="<%=Request.ServerVariables("SCRIPT_NAME")%>?save"><img src="Image/save.jpeg" width="24" height="24" border="0"></a>
</table>
0
 

Author Comment

by:LeanMoreTryMore
ID: 13787964
I suspect the bug in the following statement

 <a href="<%=Request.ServerVariables("SCRIPT_NAME")%>?save"><img src="Image/save.jpeg" width="24" height="24" border="0">


Request.ServerVariable

But i got no idea how to tackle thsi problem
0
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 13787969
<%

Response.write("<a href=" & chr(34) & Request.ServerVariables("SCRIPT_NAME") & chr(34) &"?save" & chr(34) &"><img src=" & chr(34) &"Image/save.jpeg" & chr(34) &" width=" & chr(34) &"24" & chr(34) &" height=" & chr(34) &"24" & chr(34) &" border=" & chr(34) &"0" & chr(34) &">")

%>
0
 

Author Comment

by:LeanMoreTryMore
ID: 13787981
I dont understand i change to

<a href="chr(34)<%=Request.ServerVariables("SCRIPT_NAME")%>chr(34)?save"chr(34)><img src="Image/save.jpeg" width="24" height="24" border="0"></a>


When i click on the save image, it returns error stating that "Page NOT FOUND"
0
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 13788008
That is not what I posted.

Instead of trying to write the Request.ServerVariablees("SCRIPT_NAME") in the middle of your HTML tag, write the entire anchor tag from ASP.

<%Response.write("<a href=" & chr(34) & Request.ServerVariables("SCRIPT_NAME") & chr(34) &"?save" & chr(34) &"><img src=" & chr(34) &"Image/save.jpeg" & chr(34) &" width=" & chr(34) &"24" & chr(34) &" height=" & chr(34) &"24" & chr(34) &" border=" & chr(34) &"0" & chr(34) &">")%>
0
 

Author Comment

by:LeanMoreTryMore
ID: 13788042
I got the following error
Error Type:
Microsoft JScript runtime (0x800A138F)
Object expected
/em/ReviewHRAckForm_action.asp, line 132




<table width="100%"  border="1" bgcolor="#ECECEC">
    <th scope="col"><span class="style8">Performance Management System</span><BR>
      <span class="style9"><img src="Image/spacer.gif" width="1" height="1">Performance Appraisal Form</span>
       <a href="javascript:print()"><img src="Image/tool-print.gif" width="20" height="20" border="0"></a>
     <img src="Image/spacer.gif" width="10" height="1">
    <%
Response.write("<a href=" + chr(34) + Request.ServerVariables("SCRIPT_NAME") + chr(34) +"?save" + chr(34) +"><img src=" + chr(34) +"Image/save.jpeg" + chr(34) +" width=" + chr(34)  + "24" + chr(34) + " height=" + chr(34) + "24" + chr(34) +" border=" + chr(34) +"0" + chr(34) +">")   <======== line 132
%>
</table>
0
 
LVL 29

Assisted Solution

by:rdivilbiss
rdivilbiss earned 400 total points
ID: 13788068
Sorry,

I gave you VBScript, change it to JScript.

<%Response.write('<a href="' + Request.ServerVariables("SCRIPT_NAME") + '"?save"' + '"><img src="Image/save.jpeg" width="24" height="24" border="0">')%>

It is easier to write also!
0
 

Author Comment

by:LeanMoreTryMore
ID: 13788074
MY QUESTION IS WHY IT USES MY ASP PAGE NAME AS A DOUCMENT FILE NAME AS I DID SPECIFY IN

<%
if (Request.QueryString=="save") {
    Response.Clear
    Response.ContentType = "application/msword"
     Response.addHeader("content-disposition","attachment;filename=myfrom.doc");
}
%>
0
 
LVL 11

Expert Comment

by:ajaikumarr
ID: 13788115
Hai,

I tried the same code.

<%@LANGUAGE="JSCRIPT" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
if (Request.QueryString=="save") {
    Response.Clear
    Response.ContentType = "application/msword"
     Response.addHeader("content-disposition","attachment;filename=myfrom.doc");
}
%>


<table width="100%"  border="1" bgcolor="#ECECEC">
    <th scope="col"><span class="style8">Performance Management System</span><BR>
      <span class="style9"><img src="Image/spacer.gif" width="1" height="1">Performance Appraisal Form</span>
      <a href="javascript:print()"><img src="Image/tool-print.gif" width="20" height="20" border="0"></a>
     <img src="Image/spacer.gif" width="10" height="1">
     <a href="<%=Request.ServerVariables("SCRIPT_NAME")%>?save"><img src="Image/save.jpeg" width="24" height="24" border="0"></a>
</table>

It works great.
File Name : myform.doc
File Type  : Microsoft Word Document
Form        : xxx

Bye
Ajai
0
 
LVL 11

Expert Comment

by:ajaikumarr
ID: 13788127
Hai,

1. Checkyou have word installed on your client system
2. Goto IE click Tools -> Internet options -> Advanced and click the button "Restore Defaults"

Bye
Ajai
0
 

Author Comment

by:LeanMoreTryMore
ID: 13788170
Hi Aja

I think the only reason your work is you run the page indiviaully. The same as me I create a test page and run it works fine.

But this page is called from the another page. NOT WORK
0
 

Author Comment

by:LeanMoreTryMore
ID: 13788174
But it worked before.

All of sudden not working..
i did reset the setting to default.
but it still got the same problem
0
 
LVL 11

Expert Comment

by:ajaikumarr
ID: 13788216
Hai,

Can u post the calling page code... not full code just the calling links...
like
location.href
(or)
document.action and so on.

Bye
Ajai
0
 
LVL 3

Assisted Solution

by:xiong8086
xiong8086 earned 400 total points
ID: 13788217
Maybe your condition got problem.

yours is if (Request.QueryString=="save")

try if (Request.QueryString("varName")=="save"), varName should be the parameter name passed from a form or a URL.

cheers,
Xiong
0
 

Author Comment

by:LeanMoreTryMore
ID: 13788291
i think the problem is where the save image is clicked, it calls itself but the QueryString is still stored the previous value.
It does not get into the setting section that's why the file name is the asp page name itself and file type is blank


<%
if (Request.QueryString=="save") {
    Response.Clear
    Response.ContentType = "application/msword"
     Response.addHeader("content-disposition","attachment;filename=myfrom.doc");
}
%>
 
0
 
LVL 11

Expert Comment

by:ajaikumarr
ID: 13788342
Hai,

Try this,

<%@LANGUAGE="JSCRIPT" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
if (Request.QueryString("Save")=="save") {
    Response.Clear
    Response.ContentType = "application/msword"
     Response.addHeader("content-disposition","attachment;filename=myfrom.doc");
}
%>


<table width="100%"  border="1" bgcolor="#ECECEC">
    <th scope="col"><span class="style8">Performance Management System</span><BR>
      <span class="style9"><img src="Image/spacer.gif" width="1" height="1">Performance Appraisal Form</span>
      <a href="javascript:print()"><img src="Image/tool-print.gif" width="20" height="20" border="0"></a>
     <img src="Image/spacer.gif" width="10" height="1">
     <a href="<%=Request.ServerVariables("SCRIPT_NAME")%>?save=save&rno=<%=Now()%>"><img src="Image/save.jpeg" width="24" height="24" border="0"></a>
</table>


Bye
Ajai
0
 
LVL 11

Accepted Solution

by:
ajaikumarr earned 1200 total points
ID: 13788355
Sorry,

Try this.

<%@LANGUAGE="JSCRIPT" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
if (Request.QueryString("Save")=="save") {
    Response.Clear
    Response.ContentType = "application/msword"
     Response.addHeader("content-disposition","attachment;filename=myfrom.doc");
}
%>


<table width="100%"  border="1" bgcolor="#ECECEC">
    <th scope="col"><span class="style8">Performance Management System</span><BR>
      <span class="style9"><img src="Image/spacer.gif" width="1" height="1">Performance Appraisal Form</span>
      <a href="javascript:print()"><img src="Image/tool-print.gif" width="20" height="20" border="0"></a>
     <img src="Image/spacer.gif" width="10" height="1">
     <a href="<%=Request.ServerVariables("SCRIPT_NAME")%>?save=save&rno=<%=Math.random() * 10000%>"><img src="Image/save.jpeg" width="24" height="24" border="0"></a>
</table>


Bye
Ajai
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question