开发者

ASP.Net: Generating a file to download

开发者 https://www.devze.com 2022-12-22 04:57 出处:网络
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\'v

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 convolute开发者_运维百科d and messy.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消