For Programmers: Free Programming Magazines  


Home > Archive > ASP > May 2006 > PERL to ASP conversion Read Binary Data - Replace









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author PERL to ASP conversion Read Binary Data - Replace
TRB_NV

2006-05-19, 3:56 am

I'm on a new hosted server platform which doesn't support PERL, so I'm
converting some of my old code so it'll run as ASP. I have a routine I
wrote in 1998 where I have a standard template Word file that I do some
replacing in and then fax it out to the end user. I'm trying to read the
entire file in as a string variable, but since the file isn't text it's not
getting the whole thing and I can't find a simple easy way to do it yet, so
I'm asking for help.

Below is the original PERL code that reads the contents of the entire file
to a variable called temp:

#get file from disk
$file = "contract.doc";
$temp = "";
open(MY_FILE,$file)||&error;
binmode( MY_FILE );
while ( <MY_FILE> ) {
$temp .= $_;
last if $_ eq "\n";
}
close (MY_FILE);

The text ASP equivalent is:
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(Server.MapPath("contract.doc"))
temp = f.ReadAll
f.Close
Set f = Nothing
Set fso = Nothing

What I'm trying to do though requires that I be able to read in the binary
file. I've written code to do that before, but don't have it anymore as I
didn't think I'd ever need it again. Anyone that's got some elegant code to
pass my way, would be greatly appreciated.

Thanks


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com