Need Help With TransmitFile Command In ASP.Net

Hello,

I am working on a asp.net Windows web application using Visual Studio 2008 with vb.net and the .NET 3.5 Framework.

My code is as follows:

Response.ContentType = "text/csv"
Response.AppendHeader("Content-Disposition", "attachment; filename=" & ordercode & ".csv")
If runtype = "test" Then
    Response.TransmitFile("C:\SJEData\Projects\MaxImpactEmail\Output\" & ordercode & ".csv")
    System.IO.File.Delete(("C:\SJEData\Projects\MaxImpactEmail\Output\" & ordercode & ".csv").ToString)
ElseIf runtype = "prod" Then
    Response.TransmitFile("C:\MaxImpactEmail\output\" & ordercode & ".csv")
    System.IO.File.Delete(("C:\MaxImpactEmail\output\" & ordercode & ".csv").ToString)
End If
Response.End()

The problem I'm having is that the Delete commands are not waiting for the Save File dialog to close before deleting the file.  So the file gets deleted before the user saves the file.

I need the Response.TransmitFile operation to finish before the file is deleted.

Thank you,
Stu Engelman
stuengelmanAsked:
Who is Participating?
 
CodeCruiserCommented:
Delete it next time. TransmitFile will not do anything until response is returning to the user but DeleteFile will delete straight away.
0
 
RouchieCommented:
Try setting Response.Buffer = True before transmitting.

Failing that, maybe try creating the file in memory and transmitting, so that it is removed from memory once the subroutine exits?

Orignally I used TransmitFile as well, but it caused weird behaviours in the user's browser.
0
 
stuengelmanAuthor Commented:
Nope, didn't work.  I was hoping to avoid all the streaming code.  Are there any other possibilities?
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
stuengelmanAuthor Commented:
Is the basic idea to remove the deletes from the button handler that performs the Transmits, and then set up a second button to do the deletes?
0
 
CodeCruiserCommented:
That sounds like it unless you elaborate your workflow and we may come up with something else.
0
 
stuengelmanAuthor Commented:
Hi CodeCruiser,

Will give it a try.  I think it's a nice simple solution.  I know there are other objects in the .NET Framework that freeze the code until the Save dialog is committed or cancelled, but they all require streaming the the file into memory first, which is not a big deal, but seems like a waste of effort.

Of interest is that the standard Save dialog object for .NET Windows PC applications does not have any of these constraints, but MS saw fit not to create a decent solution for .NET web applications.

Thanks, Stu
0
 
stuengelmanAuthor Commented:
Hi CodeCruiser,

Your solution works perfectly.

Thanks so much for the advice.

Stu
0
 
stuengelmanAuthor Commented:
Excellent and easy to implement solution.  Thanks so much.
0
 
CodeCruiserCommented:
Glad to help :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.