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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I know when a FSO is done saving?

Status
Not open for further replies.

mwolf00

Programmer
Nov 5, 2001
4,177
0
0
US
I have an asp page that is writing an excel file that is subsequently being attached to some emails. As it stands, the file gets attached, but is empty since the save has not completed. How can I make sure that the save is complete prior to the email loop? Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
 
it should not execute the next bit of script until your saving has been complete......
 
but the email attachments are empty (they are an excel file with the correct title - but blank).

with objCmd
.commandText = "br_sp_threeDayReport"
.CommandType = &H0004
End With

set objrs = objcmd.execute()
recCount = 0

do while not objrs.eof
if lcase(objrs(&quot;created&quot;)) <> &quot;null&quot; then
if lastName <> &quot;&quot; then
recCount = recCount + 1
if lastName <> objrs(&quot;lastName&quot;) then strOut = strOut & &quot;<tr></tr>&quot; '<
end if
lastName = objrs(&quot;lastName&quot;)
end if
strOut = strOut & objrs(0)
objrs.movenext
loop

if recCount > 0 then ' <'records found'

Set act = fso.CreateTextFile(server.mappath(g_filename), true)
with act
.WriteLine &quot;<html xmlns:x=&quot;&quot;urn:schemas-microsoft-com:eek:ffice:excel&quot;&quot;>&quot;
.WriteLine &quot;<head>&quot;
.WriteLine &quot;<!--[if gte mso 9]><xml>&quot;
.WriteLine &quot;<x:ExcelWorkbook>&quot;
.WriteLine &quot;<x:ExcelWorksheets>&quot;
.WriteLine &quot;<x:ExcelWorksheet>&quot;
.WriteLine &quot;<x:Name>Items Over 3 Days Old</x:Name>&quot;
.WriteLine &quot;<x:WorksheetOptions>&quot;
.WriteLine &quot;<x:pageSetup>&quot;
.WriteLine &quot;<x:Header>BRTT Active Requests Over 3 Days Old</x:Header>&quot;
.WriteLine &quot;</x:pageSetup>&quot;
.WriteLine &quot;<x:print>&quot;
.WriteLine &quot;<x:ValidPrinterInfo/>&quot;
.WriteLine &quot;</x:print>&quot;
.WriteLine &quot;</x:WorksheetOptions>&quot;
.WriteLine &quot;</x:ExcelWorksheet>&quot;
.WriteLine &quot;</x:ExcelWorksheets>&quot;
.WriteLine &quot;</x:ExcelWorkbook>&quot;
.WriteLine &quot;</xml>&quot;
.WriteLine &quot;<![endif]--> &quot;
.WriteLine &quot;</head>&quot;
.WriteLine strOut
end with
act.close


'now mail them'

strSQL = &quot;SELECT firstName, email &quot;&_
&quot;FROM tblPerson p JOIN tbmPersonRole r on p.personID = r.personID &quot;&_
&quot;WHERE r.roleID = (select roleID from tblRole where roleName='Administrator')&quot;
set objrs = objconn.execute(strSQL)

do while not objrs.eof
set objMail = server.createObject(&quot;CDONTS.newMail&quot;)
with objMail
.From = &quot;joeblow@abc.com&quot;
.To = objrs(&quot;email&quot;)
.Subject = &quot;Daily Report - Requests Over 3 days Old&quot;
strOut = objrs(&quot;firstName&quot;) &_
&quot;, <br><br>Your daily report for BRTT requests over 3 days old (starting 3/24/03) is attached.<br>&quot;&_
&quot;The total number of records found is &quot; & recCount & &quot;.<br><br><br>&quot;
.Body = strOut
.AttachFile (server.mappath(g_filename ))
.bodyFormat = 0 'HTML'
.mailFormat = 0 'MIME Format'
.send
end with
objrs.movenext
loop
end if 'records found' Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
 
Am I missing something? I don't see where you are actually writing any data to the spreadsheet? --James
 
James,

All of the act.WriteLines write to the file. The file is created correctly, I can see it when the code is done running.... Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
 
Here's something interesting. When I write the oFile.size on the first pass (after act.close), the file size is correct (32K) which indicates that the entire file has indeed saved. Why is the attachment still empty (0 Bytes)? Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
 
I've hardcoded an existing file into the objMail.attachFile line and I still get an empty folder - so that's where the problem is - any ideas on why the contents get left out? Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
 
Here's the problem!!!

.mailFormat = 0 'MIME Format'

If I comment this line out, the code works perfectly...

Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
 
The necessary mailFormat is actually dependant on the encoding of the attachment. I don't remember the specifics but I think that if the attachment is encoded in base 64 format the mailformat will actually be change for you to MIME format, however if you set the mailformat to text, the UUEncode format is only default while setting it to MIME means that it expects a base 64 file by default. I don't see where any of this could be the cause of your problem, but it may be that I am forgetting something here.

-Tarwn [sub]01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101 [/sub]
[sup]29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19[/sup]
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 
Thanks Tarwyn, but the mail format was definitely the problem. I'm not sure what I should set it to, so I'm ignoring it and the attachment is working fine. The only downside is that I cannot send the mail as HTML, it has to be plain text...

Thanks to everyone for the help! Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top