Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //for very big files use HttpReponse.TransmitFile() http://msdn.microsoft.com/en-us/library/12s31dhy(v=vs.80).aspx
- protected void SendFileToResponse(string physicalPath, string fileName)
- {
- //se si presenta il problema della cache del browser si può appendere una querystring casuale in modo da far ricaricare
- CurrentContext.Response.ContentType = FileContentType; //"application/pdf", "image/png"
- string tmp = "inline";
- if (CurrentContext.Request.QueryString["d"] == "1")
- {
- tmp = "attachment";
- }
- CurrentContext.Response.AddHeader("Content-Disposition", string.Format("{1}; filename={0}", fileName, tmp));
- using (Stream s = new FileStream(physicalPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
- {
- s.CopyTo(CurrentContext.Response.OutputStream);
- }
- if (CurrentContext.Response.IsClientConnected)
- {
- CurrentContext.Response.Flush();
- }
- }
- private void SendStreamToResponse(MemoryStream stream, string fileName)
- {
- //se si presenta il problema della cache del browser si può appendere una querystring casuale in modo da far ricaricare
- CurrentContext.Response.ContentType = FileContentType; //"application/pdf", "image/png"
- string tmp = "inline";
- if (CurrentContext.Request.QueryString["d"] == "1")
- {
- tmp = "attachment";
- }
- CurrentContext.Response.AddHeader("Content-Disposition", string.Format("{1}; filename={0}", fileName, tmp));
- //stream is disposed by method caller
- stream.WriteTo(CurrentContext.Response.OutputStream);
- if (CurrentContext.Response.IsClientConnected)
- {
- CurrentContext.Response.Flush();
- }
- }
Add Comment
Please, Sign In to add comment