using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
namespace SampleCS.Upload
{
///
/// Down¿¡ ´ëÇÑ ¿ä¾à ¼³¸íÀÔ´Ï´Ù.
///
public class Down : System.Web.UI.Page
{
string strFileName = String.Empty;//³Ñ°ÜÁ®¿Â ÆÄÀϸí ÀúÀå
string strBaseDir = String.Empty;//¾îµð¿¡ ÀúÀåÇÒ Æú´õ¸í
private void Page_Load(object sender, System.EventArgs e)
{
strFileName = Request.QueryString["FileName"].ToString();
strBaseDir = Server.MapPath(".") + @"\files";
if(strFileName == null) //³Ñ°ÜÁ®¿Â ÆÄÀϸíÀÌ ¾ø´Ù¸é...
{
Response.End();//¸ØÃã
}
else //°Á¦ ´Ù¿î·Îµå
{
Response.Clear();//¹öÆÛ ºñ¿ì±â
Response.ContentType = "application/octet-stream";
Response.AddHeader(
"Content-Disposition",
"attachment;filename=" +
Server.UrlPathEncode(strFileName));
Response.WriteFile(
Path.Combine(strBaseDir, strFileName));
//´Ù¿îȽ¼ö Áõ°¡
UpdateDownCount();//´Ù¿î Ƚ¼ö Áõ°¡ ÇÔ¼ö È£Ãâ
Response.End();//¹öÆÛ ºñ¿ì°í, Á¾·á.
}
}
private void UpdateDownCount()
{
SqlConnection objCon = new SqlConnection();
objCon.ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["CONNECTION_STRING"].ToString();
objCon.Open();
SqlCommand objCmd = new SqlCommand();
objCmd.Connection = objCon;
objCmd.CommandText = "Update Upload Set DownCount = DownCount + 1 Where FileName = @FileName";
objCmd.Parameters.Add(new SqlParameter("@FileName", strFileName));
objCmd.CommandType = CommandType.Text;
objCmd.ExecuteNonQuery();
objCon.Close();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: ÀÌ È£ÃâÀº ASP.NET Web Form µðÀÚÀ̳ʿ¡ ÇÊ¿äÇÕ´Ï´Ù.
//
InitializeComponent();
base.OnInit(e);
}
///
/// µðÀÚÀÌ³Ê Áö¿ø¿¡ ÇÊ¿äÇÑ ¸Þ¼µåÀÔ´Ï´Ù.
/// ÀÌ ¸Þ¼µåÀÇ ³»¿ëÀ» ÄÚµå ÆíÁý±â·Î ¼öÁ¤ÇÏÁö ¸¶½Ê½Ã¿À.
///
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}