views:

104

answers:

2

I have a file that I need to copy, run a command against the copy that specializes it for the person downloading it, and then provide that copy to a user to download. I'm using ASP.Net MVC2, and I've never done anything like this. I've searched around for the simplest way to do it, but I haven't found much, so I've come up with a plan.

I think what I'll do is generate a guid, which will become the name of a folder I'll generate at the same level of the source file that the copy is made from. I'll then copy the file to that folder, run my command against it, provide a link to the file, and I'll have some service that runs every now and then that deletes directories that are more than a day old.

Am I over thinking this? Is there an easier, simpler, or at least more formal way to do this? My way seems a bit convoluted and messy.

+2  A: 

Can you process in memory and stream it to the client with a handler?

That is how I do things like this.

Basically, your download link points to an HttpHandler, typically async, that performs the processing and then streams the bits with a content-disposition of 'attachment' and a filename.

EDIT: I don't do much MVC but what Charles is describing sounds like and MVC version what I describe above.

Either way, processing in memory and streaming it out is probably your best bet. It obviates a lot of headaches, code and workflow you would have to maintain otherwise.

Sky Sanders
+1  A: 

What sort of command do you have to run against it?

Because it would be ideal to process it in memory in a controller's action using MVC's FileResult to send it to the client.

Charles

Charlino
Well, I'd like to run a windows installer SQL query on it, but I'm struggling to find out how to do that in .Net. It looks like there's an API, but I can't seem to find where to download it. I'd love to just do it all in code like that.
Mike Pateras
Hmmm ok, I've haven't got any experience doing that sort of stuff. You might be better off asking another question about how to do something like that in memory and then use that knowledge to return a `FileResult`. I've added a couple of tags to the question to maybe help out a bit.
Charlino