Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Text;
- using System.Web;
- using System.Web.UI;
- public partial class _Default : Page
- {
- protected override void OnInit(EventArgs e)
- {
- string str1 = ResolveUrl("~/image.jpg");
- string str2 = this.Server.MapPath(str1);
- string str = HttpUtility.UrlEncode(Path.GetFileName(str2), Encoding.UTF8).Replace("+", "%20");
- this.Response.ContentType = "image/jpeg";
- this.Response.AddHeader("Content-Disposition", "filename=" + str);
- using (Stream stream = new FileStream(str2, FileMode.Open, FileAccess.Read, FileShare.Read))
- {
- this.Response.Cache.SetExpires(DateTime.Now.AddYears(-1));
- long lengthLeft = stream.Length;
- byte[] buffer = new byte[8192];
- while (lengthLeft > 0L && this.Response.IsClientConnected)
- {
- int count = stream.Read(buffer, 0, 8192);
- this.Response.OutputStream.Write(buffer, 0, count);
- this.Response.Flush();
- lengthLeft -= (long)count;
- }
- }
- base.OnInit(e);
- }
- }
- <%@ Page Title="Home Page" Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
- <?xml version="1.0" encoding="utf-8"?>
- <configuration>
- <system.web>
- <authentication mode="None" />
- <compilation debug="false" />
- </system.web>
- </configuration>
Add Comment
Please, Sign In to add comment