1
using System;
2
using Microsoft.Practices.EnterpriseLibrary.Data;
3
using System.IO;
4
5
public partial class Upload_WriteControl : System.Web.UI.UserControl ...{
6
protected void Page_Load(object sender, EventArgs e)
7
...{
8
// Empty
9
}
10
private string GetFilePath(string strBaseDirTemp, string strFileNameTemp) ...{
11
string strName = //순수파일명 : Test
12
Path.GetFileNameWithoutExtension(strFileNameTemp);
13
string strExt = //확장자 : .txt
14
Path.GetExtension(strFileNameTemp);
15
bool blnExists = true;
16
int i = 0;
17
while (blnExists) ...{
18
//Path.Combine(경로, 파일명) = 경로+파일명
19
if (File.Exists(Path.Combine(strBaseDirTemp, strFileNameTemp))) ...{
20
strFileNameTemp =
21
strName + "(" + ++i + ")" + strExt;//Test(3).txt
22
}
23
else ...{
24
blnExists = false;
25
}
26
}
27
return strFileNameTemp;
28
}
29
protected void btnWrite_Click(object sender, EventArgs e) ...{
30
// 파일 업로드
31
string strDirectory = Server.MapPath(".") + "\\files\\"; //
32
string strFileName = String.Empty;
33
if (!String.IsNullOrEmpty(ctlFileName.FileName))
34
...{
35
// 파일명 추출
36
strFileName =
37
GetFilePath(strDirectory, ctlFileName.FileName);
38
// 경로 및 파일명으로 저장 실행
39
ctlFileName.PostedFile.SaveAs(
40
Path.Combine(strDirectory, strFileName));
41
}
42
// DB 저장
43
DatabaseFactory.CreateDatabase("ConnectionString").
44
ExecuteNonQuery("WriteUpload"
45
, txtName.Text
46
, txtEmail.Text
47
, txtTitle.Text
48
, Request.UserHostAddress
49
, txtContent.Text
50
, txtPassword.Text
51
, lstEncoding.SelectedValue
52
, txtHomepage.Text
53
, strFileName // 변경...
54
, ctlFileName.PostedFile.ContentLength // 파일사이즈
55
);
56
btnList_Click(null, null);
57
}
58
protected void btnList_Click(object sender, EventArgs e)
59
...{
60
// 이동
61
Response.Redirect("List.aspx");
62
}
63
}
64