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