ASP.NET 기초 강의실

시삽: 레드플러스 님 
게시판 이동:
 제목 : Write.ascx.cs
글번호: 271
작성자: 레드플러스
작성일: 2008/07/09 오전 10:43:00
조회수: 4026

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


관련 아티클 리스트
  제       목 파일 작성자 작성일 조회
이전글 [!] 사진 게시판 : /WebPhoto/ - 레드플러스 2008-07-10 7295
  [!] 자료실 게시판 만들기 : Enterprise Library V4.0 사용 - 레드플러스 2008-07-09 7392
  [1] File->New Website : 솔루션 탐색기 모양 WebUploadEL.jpg(32 KB) 레드플러스 2008-07-09 4618
  [2] 테이블(Table) 및 저장 프로시저(Stored Procedure) - 레드플러스 2008-07-09 4789
  [3] 입력페이지 작성 : Write.ascx - 레드플러스 2008-07-09 4288
현재글 Write.ascx.cs - 레드플러스 2008-07-09 4026
  [4] 출력페이지 작성 : List.ascx - 레드플러스 2008-07-09 4391
  List.ascx.cs - 레드플러스 2008-07-09 3913
  [5] 상세페이지 작성 : View.ascx - 레드플러스 2008-07-09 4502
  Re : View.ascx - 레드플러스 2008-07-09 3675
  [6] 수정페이지 작성 : Modify.ascx - 레드플러스 2008-07-09 3924
  Modify.ascx.cs - 레드플러스 2008-07-09 3651
  [7] 삭제페이지 작성 : Delete.ascx - 레드플러스 2008-07-09 4133
  Delete.ascx.cs - 레드플러스 2008-07-09 3568
  [8] 검색페이지 작성: Search.ascx - 레드플러스 2008-07-09 3963
  Search.ascx.cs - 레드플러스 2008-07-09 3591
다음글 [!] 기본형 게시판 만들기(Enterprise Library V4.X) : /Web... - 레드플러스 2008-07-07 7605
 
손님 사용자 Anonymous (손님)
로그인 Home