ASP.NET 기초 강의실

시삽: 레드플러스 님 
게시판 이동:
 제목 : Modify.ascx.cs
글번호: 276
작성자: 레드플러스
작성일: 2008/07/09 오후 2:34:00
조회수: 3669

1using System; 2using System.Data; 3using System.Web.UI; 4using Microsoft.Practices.EnterpriseLibrary.Data; 5using System.IO; 6 7public 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
 
이전 글   다음 글 삭제 수정 답변 글쓰기 리스트


관련 아티클 리스트
  제       목 파일 작성자 작성일 조회
이전글 [!] 사진 게시판 : /WebPhoto/ - 레드플러스 2008-07-10 7308
  [!] 자료실 게시판 만들기 : Enterprise Library V4.0 사용 - 레드플러스 2008-07-09 7403
  [1] File->New Website : 솔루션 탐색기 모양 WebUploadEL.jpg(32 KB) 레드플러스 2008-07-09 4634
  [2] 테이블(Table) 및 저장 프로시저(Stored Procedure) - 레드플러스 2008-07-09 4805
  [3] 입력페이지 작성 : Write.ascx - 레드플러스 2008-07-09 4306
  Write.ascx.cs - 레드플러스 2008-07-09 4042
  [4] 출력페이지 작성 : List.ascx - 레드플러스 2008-07-09 4407
  List.ascx.cs - 레드플러스 2008-07-09 3930
  [5] 상세페이지 작성 : View.ascx - 레드플러스 2008-07-09 4521
  Re : View.ascx - 레드플러스 2008-07-09 3693
  [6] 수정페이지 작성 : Modify.ascx - 레드플러스 2008-07-09 3946
현재글 Modify.ascx.cs - 레드플러스 2008-07-09 3669
  [7] 삭제페이지 작성 : Delete.ascx - 레드플러스 2008-07-09 4150
  Delete.ascx.cs - 레드플러스 2008-07-09 3583
  [8] 검색페이지 작성: Search.ascx - 레드플러스 2008-07-09 3982
  Search.ascx.cs - 레드플러스 2008-07-09 3606
다음글 [!] 기본형 게시판 만들기(Enterprise Library V4.X) : /Web... - 레드플러스 2008-07-07 7618
 
손님 사용자 Anonymous (손님)
로그인 Home