Método Response.TransmitFile
Para transmitir archivos a un cliente, generalmente se usaba el siguiente código:
string file = Request.Params["file"];
if (!string.IsNullOrEmpty(file))
{
file = Path.Combine(Server.MapPath("downloads"), Path.GetFileName(file));
Response.Clear();
Response.ContentType = "application/octect-stream";
Response.AddHeader("Content–Disposition", "attachment; filename=foo.xyz");
Response.WriteFile(file);
Response.End();
}
Pero cuando los archivos son muy grandes trae problemas.
En ASP.NET 2.0 existe un nuevo método que soluciona estos problemas
string file = Request.Params["file"];
if (!string.IsNullOrEmpty(file))
{
file = Path.Combine(Server.MapPath("downloads"), Path.GetFileName(file));
Response.Clear();
Response.ContentType = "application/octect-stream";
Response.AddHeader("Content–Disposition", "attachment; filename=foo.xyz");
Response.TransmitFile(file);
Response.End();
}
Etiquetas: C#

0 Comentarios:
Publicar un comentario
Suscribirse a Comentarios de la entrada [Atom]
<< Página Principal