Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBscript function problem?

Status
Not open for further replies.

jon2002

Technical User
Jun 26, 2002
13
GB
Hi all

This following line is generated from a ASP file but when ever you click on it you get a "type mismatch error". File_Open is a function from the MSDN site, the code works fine with a hard coded file name but since I have changed it to a function I get errors.

<a href=&quot;#&quot; onclick=&quot;vbscript:File_Open('_148074869_TEST.doc')&quot; >test</a>

<%

Function File_Open(docref)

Response.buffer = TRUE
Response.ContentType = &quot;application/msword&quot;

Dim vntStream

Set oMyObject = Server.CreateObject(&quot;MyObject.BinRead&quot;)

vntStream = oMyObject.readBinFile(&quot;D:\Data\document_references\&quot; & docref)

Response.BinaryWrite(vntStream)

Set oMyObject = Nothing

Response.End

End Function

%>

Thanks in advance

Jon
 
Isn't this supposed to be client-side script?

<SCRIPT LANGUAGE=VBSCRIPT >
</SCRIPT>
 
Thank you
I have done that and am now getting a syntax error when I click on the link :-

<a href='vbscript:FileOpen(&quot;_148074869_TEST.doc&quot;);' target=&quot;_blank&quot; >test</a>

Thanks again your help is most appreciated!
Jon
 
OK - I see what you are trying to do and I can't be much help to you - I have not used response.contenttype before.

I have no other suggestion than to suggest that you call a second page and send the docref to it. In the second page you can use server side scripts to open the doc.

<%
Response.buffer = TRUE
Response.ContentType = &quot;application/msword&quot;
etc...
%>

I am very sorry.
 
Thats Ok

could you explain how I would open another and send doc ref to it, sorry to be a pain but I am quite new to tis and have been &quot;dumped in it&quot; so to speak

Cheers
Jon
 
I am kind of new to this also, therefore I cannot be much help to you without writing these pages myself and then posting questions to this forum to help me out ;)

I think I may have messed you up by responding to your question in the first place because - sometimes when people see responses, they don't always look to see if you still need help.

I am not sure how this site feels about this - but it is possible that you may want to rephrase your question and post it again.
 
No thats cool I think you have pointed me in the right direction, so thank you!!

All the Best
Jon
 
Actually that should be server side script. What you are trying to do is force someone to download a given file by setting the header type and then binary writing the file to the output stream. The problem is that you are trying to call it from the client, which won't work. Try using javascript or something similar to open a new window pointed at a page that contains nothing but the ASP script:
Code:
Page1:

<a href=&quot;#&quot; onClick=&quot;window.open('download.asp?filename=_148074869_TEST.doc);&quot;>Download!</a>

Download.asp:
<%
Option Explicit

Dim docref
docref = Request.QueryString(&quot;filename&quot;)
    
   Response.buffer = TRUE
   Response.ContentType = &quot;application/msword&quot;

   Dim vntStream

   Set oMyObject = Server.CreateObject(&quot;MyObject.BinRead&quot;)

   vntStream = oMyObject.readBinFile(&quot;D:\Data\document_references\&quot; & docref)

   Response.BinaryWrite(vntStream)

   Set oMyObject = Nothing

   Response.End
%>

That should work if you pass it the name of a valid file and if my javascript window.open works. Or you could just set the link in the first file to be:
Code:
<a href=&quot;Download.asp?filename=_148074869_TEST.doc&quot;> Download! </a>
to achieve the same effect.
-Tarwn If your happy and you know it...
 
Brilliant thank you Tarwn!!!!
Its working

Regards
Jon
 
I am really glad someone jumped in - sorry for misleading you with my initial question.

I am stuck with client / server side issues right now.

[morning]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top