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!

Scripting.FileSystemObject and Readline

Status
Not open for further replies.

Taco

Programmer
Apr 1, 2001
32
US
I have successfully in the past used this code to send HTML formatted emails from my ASP application. Recently the code is now inserting a </html> after each line it reads from the file. This is causing problems with email clients like Lotus Notes. It use to just read the file line by line and insert that into the body of an email message. Please help!! Here is the code:

If HTMLChk = &quot;on&quot; then
Mailer.ContentType = &quot;text/html&quot;
If oUpl.IsEmpty = False Then
NewFileName = Mid(oUpl.UserFilename, InstrRev(oUpl.UserFilename, &quot;\&quot;) + 1)
oUpl.SaveAs NewFileName
FileName2 = oUpl.ServerName
SendMessage = &quot;&quot;
Dim fObj, f
Set fObj = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
if fObj.FileExists(FileName2) then
Set f = fObj.OpenTextFile(FileName2,1,FALSE,FALSE)
Do until f.AtEndOfStream = True
SendMessage = SendMessage & f.ReadLine & &quot;</html>&quot; & vbCrLf
Loop
end if
Set fOBj = nothing
End If
 
It looks like the you are adding a closing HTML tag after each line of the stream. Try looping through the stream and continue to concatenate the SendMessage string. After the loop is finished, then add the closing HTML tag.

Do until f.AtEndOfStream = True
SendMessage = SendMessage & f.ReadLine & vbCrLf
Loop
SendMessage = SendMessage & &quot;</html>&quot;

Some html readers such as outlook and internet explorer are not as strict about their html tags and their placements. You say that this worked before, well could it be that the reader was not very strict its interpretation and that every line did in fact end with a closing html tag.





 
It had previously worked before without actually writing the </html> - that was used in the do until </html>. And I have a saved message from a few months ago, when I look at the source code of the email there is no </html> except the last one at the end of the html file that the code is reading. I sent that same HTML file again and now it adds the </html> after each line, which I really don't understand since it is opening the file ForReading (1)??

I did just change the code a little - I commented out the do until loop and added the readall instead of reading line by line and it seems to be working - even faster!!

if fObj.FileExists(FileName2) then
Set f = fObj.OpenTextFile(FileName2,1,FALSE,FALSE)
SendMessage = f.ReadAll
f.close
'Do until f.AtEndOfStream = True
'SendMessage = SendMessage & f.ReadLine & &quot;</html>&quot; & vbCrLf
'Loop
end if

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top