1
using System;
2
using System.Data;
3
using System.Web.UI;
4
using Microsoft.Practices.EnterpriseLibrary.Data;
5
using System.IO;
6
7
public partial class Upload_ModifyControl : System.Web.UI.UserControl
8
...{
9
protected void btnModify_Click(object sender, EventArgs e)
10
...{
11
// 파일 업로드
12
string strDirectory = Server.MapPath(".") + "\\files\\"; //
13
string strFileName = String.Empty;
14
if (!String.IsNullOrEmpty(ctlFileName.FileName))
15
...{
16
// 파일명 추출
17
strFileName =
18
GetFilePath(strDirectory, ctlFileName.FileName);
19
// 경로 및 파일명으로 저장 실행
20
ctlFileName.PostedFile.SaveAs(
21
Path.Combine(strDirectory, strFileName));
22
}
23
// DB 수정
24
int result = DatabaseFactory.CreateDatabase("ConnectionString").
25
ExecuteNonQuery("ModifyUpload"
26
, txtName.Text, txtEmail.Text
27
, txtTitle.Text, Request.UserHostAddress
28
, DateTime.Now, txtContent.Text
29
, lstEncoding.SelectedValue, txtHomepage.Text
30
, txtPassword.Text, strFileName
31
, ctlFileName.PostedFile.ContentLength
32
, Request["Num"]
33
);
34
if (result == -1) ...{
35
lblError.Text = "암호가 틀립니다.";
36
}
37
else ...{
38
btnCancel_Click(null, null);
39
}
40
}
41
private string GetFilePath(string strBaseDirTemp, string strFileNameTemp)
42
...{
43
string strName = //순수파일명 : Test
44
Path.GetFileNameWithoutExtension(strFileNameTemp);
45
string strExt = //확장자 : .txt
46
Path.GetExtension(strFileNameTemp);
47
bool blnExists = true;
48
int i = 0;
49
while (blnExists)
50
...{
51
//Path.Combine(경로, 파일명) = 경로+파일명
52
if (File.Exists(Path.Combine(strBaseDirTemp, strFileNameTemp)))
53
...{
54
strFileNameTemp =
55
strName + "(" + ++i + ")" + strExt;//Test(3).txt
56
}
57
else
58
...{
59
blnExists = false;
60
}
61
}
62
return strFileNameTemp;
63
}
64
protected void Page_Load(object sender, EventArgs e)
65
...{
66
if (String.IsNullOrEmpty(Request["Num"]))
67
...{
68
Response.Write("잘못된 요청입니다.");
69
Response.End();
70
}
71
else
72
...{
73
if (!Page.IsPostBack) // 처음 로드할 때만 예전 데이터 읽어오기
74
...{
75
DisplayData();
76
}
77
}
78
}
79
private void DisplayData()
80
...{
81
using (IDataReader dr = DatabaseFactory.CreateDatabase(
82
"ConnectionString").ExecuteReader(
83
"ViewUpload", Request["Num"]))
84
...{
85
while (dr.Read())
86
...{
87
lblNum.Text = dr[0].ToString();
88
txtName.Text = dr["Name"].ToString();
89
txtEmail.Text = dr.GetString(2);
90
txtTitle.Text = dr["Title"].ToString();
91
txtHomepage.Text = dr["Homepage"].ToString();
92
txtContent.Text = dr["Content"].ToString();//***
93
// 인코딩
94
// 예전에 선택했던 인코딩 지정 : 0, 1, 2 중 하나 인덱스
95
if (dr["Encoding"].ToString() == "HTML") ...{
96
lstEncoding.SelectedIndex = 1;
97
}
98
else if (dr["Encoding"].ToString() == "Mixed") ...{
99
lstEncoding.SelectedIndex = 2;
100
}
101
else ...{
102
lstEncoding.SelectedIndex = 0; // Text
103
}
104
}
105
}
106
}
107
protected void btnCancel_Click(object sender, EventArgs e)
108
...{
109
// 상세 보기로 이동
110
Response.Redirect("View.aspx?Num=" + Request["Num"]);
111
}
112
}
113