Source code location: ./file_download/localdownloadserver.cs
class LocalDownloadServer : IDownloadServer { public void ServeFile (File file) { PageAsyncTask task = new PageAsyncTask (new BeginEventHandler (StartSending), new EndEventHandler (EndSending), null, file); ((Page) HttpContext.Current.Handler).RegisterAsyncTask (task); } // --------------------------------------------------------------------------------------- private IAsyncResult StartSending (object sender, EventArgs e, AsyncCallback cb, object extraData) { HttpContext ctx = HttpContext.Current; HttpResponse response = ctx.Response; File file = (File) extraData; byte[] data = FileBL.GetFileImage (file.PrimaryKey); ctx.ClearError (); response.Clear (); response.AddHeader ("Content-Disposition", "attachment; filename=\"" + file.Name +"\""); response.ContentType = file.ContentType; response.StatusCode = 200; return response.OutputStream.BeginWrite (data, 0, (int) file.Size, cb, null); } // --------------------------------------------------------------------------------------- private void EndSending (IAsyncResult ar) { HttpContext ctx = HttpContext.Current; HttpResponse response = ctx.Response; response.OutputStream.EndWrite (ar); response.OutputStream.Close (); } }
Copyright © 2004-2006, Milan Negovan. All rights reserved. | License
Back to AspNetResources.com