Guest User

Untitled

a guest
Aug 20th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Text;
  4. using System.Web;
  5. using System.Web.UI;
  6. public partial class _Default : Page
  7. {
  8. protected override void OnInit(EventArgs e)
  9. {
  10. string str1 = ResolveUrl("~/image.jpg");
  11. string str2 = this.Server.MapPath(str1);
  12.  
  13. string str = HttpUtility.UrlEncode(Path.GetFileName(str2), Encoding.UTF8).Replace("+", "%20");
  14. this.Response.ContentType = "image/jpeg";
  15. this.Response.AddHeader("Content-Disposition", "filename=" + str);
  16. using (Stream stream = new FileStream(str2, FileMode.Open, FileAccess.Read, FileShare.Read))
  17. {
  18. this.Response.Cache.SetExpires(DateTime.Now.AddYears(-1));
  19. long lengthLeft = stream.Length;
  20. byte[] buffer = new byte[8192];
  21. while (lengthLeft > 0L && this.Response.IsClientConnected)
  22. {
  23. int count = stream.Read(buffer, 0, 8192);
  24. this.Response.OutputStream.Write(buffer, 0, count);
  25. this.Response.Flush();
  26. lengthLeft -= (long)count;
  27. }
  28. }
  29. base.OnInit(e);
  30. }
  31. }
  32.  
  33. <%@ Page Title="Home Page" Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
  34.  
  35. <?xml version="1.0" encoding="utf-8"?>
  36. <configuration>
  37. <system.web>
  38. <authentication mode="None" />
  39. <compilation debug="false" />
  40. </system.web>
  41. </configuration>
Add Comment
Please, Sign In to add comment