using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;
/// <summary>
/// BoardDown : 완성형(DotNetNote) 게시판의 강제다운로드 페이지
/// </summary>
public partial class DotNetNote_BoardDown : System.Web.UI.Page
{
#region Private Member Variables
private int intNum;
private string strFileName = "";
private string strBaseDir = "";
#endregion
#region Event Handlers
protected void Page_Load(object sender, System.EventArgs e)
{
intNum = Convert.ToInt32(
Request.QueryString["Num"].ToString());
SqlConnection objCon = new SqlConnection(
ConfigurationManager.ConnectionStrings[
"ConnectionString"].ConnectionString);
objCon.Open();
SqlCommand objCmd = new SqlCommand(
"Select FileName From DotNetNote Where Num = "
+ intNum.ToString(), objCon);
strFileName = objCmd.ExecuteScalar().ToString();
objCon.Close();
// 다운로드 폴더 지정
strBaseDir = Server.MapPath("./MyFiles/");
if (strFileName == null)
{
Response.Redirect("./BoardList.aspx");
}
else
{
//강제 다운로드 창 띄우기 주요 로직
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename="
+ Server.UrlPathEncode(strFileName));
Response.WriteFile(strBaseDir + strFileName);
UpdateDownCount();//
Response.End();
}
}
#endregion
#region Private Methods
// 다운수 증가 로직
private void UpdateDownCount()
{
SqlConnection objCon = new SqlConnection();
objCon.ConnectionString =
ConfigurationManager.ConnectionStrings[
"ConnectionString"].ConnectionString;
objCon.Open();
SqlCommand objCmd = new SqlCommand();
objCmd.Connection = objCon;
objCmd.CommandText =
"Update DotNetNote Set DownCount = DownCount + 1 "
+ "Where FileName = '" + strFileName + "'";
objCmd.CommandType = CommandType.Text;
objCmd.ExecuteNonQuery();
objCon.Close();
objCon = null;
}
#endregion
} |