ASP.NET 기초 강의실

시삽: 레드플러스 님 
게시판 이동:
 제목 : PhotoAdd.ascx.cs
글번호: 285
작성자: 레드플러스
작성일: 2008/07/10 오후 12:07:00
조회수: 4583

1using System; 2using System.IO; 3using Microsoft.Practices.EnterpriseLibrary.Data; 4using System.Data; 5 6public partial class Photo_PhotoAddControl : System.Web.UI.UserControl 7{ 8 protected void Page_Load(object sender, EventArgs e) 9 { 10 // Empty 11 } 12 protected void btnAdd_Click(object sender, EventArgs e) { 13 // 파일첨부 확인 14 if (ctlFileName.PostedFile.ContentLength > 0) { 15 // 파일 용량 제한 16 if (ctlFileName.PostedFile.ContentLength <= (1048576 * 4)) { 17 // 파일 확장자 검사 : 이미지 파일만 업로드 18 string ext = Path.GetExtension(ctlFileName.FileName); 19 if (ext == ".gif" || ext == ".jpg" 20 || ext == ".jpeg" || ext == ".png") { 21 //[1] 중복파일 제거 후 사진 업로드 22 파일업로드/파일명 중복 처리 후 업로드 37 //[2] DB에 데이터 저장 38 string sql = String.Format(@" 39Insert Into Photos 40 (Name, Title, Content, PostIP, Password, Category, FileName, FileSize) 41Values 42 ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}')" 43 , txtName.Text 44 , txtTitle.Text 45 , txtContent.Text 46 , Request.UserHostAddress 47 , txtPassword.Text 48 , lstCategory.SelectedValue 49 , strFileName 50 , ctlFileName.PostedFile.ContentLength 51 ); 52 DatabaseFactory.CreateDatabase("ConnectionString") 53 .ExecuteNonQuery(CommandType.Text, sql); // DB저장 54 Response.Redirect("PhotoList.aspx"); // 이동 55 } 56 else { lblError.Text = "이미지 파일만 업로드하세요."; } 57 } 58 else { // 4096 Kbytes 이상 자료를 업로드 하고자한다면, 59 // http://support.microsoft.com/kb/815307/ko 60 lblError.Text = "4MB 이하만 업로드 가능합니다."; 61 } 62 } 63 else { lblError.Text = "사진을 첨부하셔야 합니다."; } 64 } 65 66 중복된 파일명 뒤에 번호 붙이는 메서드 : GetFilePath 98} 99
 
이전 글   다음 글 삭제 수정 답변 글쓰기 리스트


관련 아티클 리스트
  제       목 파일 작성자 작성일 조회
이전글 [!] 답변형 게시판 : /WebReply/ - 레드플러스 2008-07-14 5468
  [!] 사진 게시판 : /WebPhoto/ - 레드플러스 2008-07-10 7295
  테이블 및 저장 프로시저 - 레드플러스 2008-07-10 5266
  PhotoAdd.ascx - 레드플러스 2008-07-10 4708
현재글 PhotoAdd.ascx.cs - 레드플러스 2008-07-10 4583
  ThumbNail.ascx - 레드플러스 2008-07-10 4285
  ThumbNail.ascx.cs - 레드플러스 2008-07-10 4422
다음글 [!] 자료실 게시판 만들기 : Enterprise Library V4.0 사용 - 레드플러스 2008-07-09 7392
 
손님 사용자 Anonymous (손님)
로그인 Home