• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 719
  • Last Modified:

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
0
stuengelman
Asked:
stuengelman
  • 5
  • 3
1 Solution
 
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
 
CodeCruiserCommented:
Delete it next time. TransmitFile will not do anything until response is returning to the user but DeleteFile will delete straight away.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now