블로그 이미지
Magic_kit
study 관련자료를 한곳으로 자기 개발 목적으로 재태크 재무 관리 목적으로 일상생활의 팁을 공유 하기 위하여 블로그를 개설 하였습니다.

calendar

1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28

Category

Recent Post

Recent Comment

Archive

2009. 10. 8. 12:26 .Net Project/ASP.NET 3.5 Sp1
반응형
 FrmFileUpload.aspx 디자인 모드

 




- 파일 업로드시 업로드 하여 저장 할 폴더를 지정하기 위하여 "file" 폴더 생성

- 폴더의 속성은 권한설정이 필요한데 사용자 "쓰기권한" 이상을 체크 하여한다. 

- 업로드 순서 -> 찾아보기 버튼 클릭하여 파일을 선택(대용량 파일) 하여 파일 업로드 

- 실행할 경우 레이블에 "유이.png"라는 파일이 표시되는것을 확인 가능 

- 확인우 파일을 클릭 후 다운로드 혹은 이미지 새로운 웹사이트 실행하여 이미지를 
   자세히 확인 가능 하다. 

- 파일업로드 후 파일 사이즈가 레이블에 표시되는것을 확인 할 수 있으며 파일 선택하지
   않고 업로드시 "파일을 선택해주십시오" 라는 메시지를 화면에 출력 
  
- 업로드 완료시 "업로드 완료 되었습니다" 라는 메시지가 출력된다 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FrmFileUpload.aspx.cs" Inherits="_10월8일_FrmFileUpload" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>제목 없음</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <img src="../Image/윤아.png" width="100" height="100" />
        <img src="../Image/유이.png" width="100" height="100" /><br />
        &nbsp;<asp:FileUpload ID="FileUpload1" runat="server" />
        <asp:Button ID="Button1" runat="server" Text="파일업로드" Height="19px"
            onclick="Button1_Click" />
        <asp:Label ID="Label1" runat="server" Text="Label"
                              ForeColor="Red"></asp:Label>
    </div>
    </form>
</body>
</html>




 FrmFileUplad.aspx.Cs 이벤트 컨트롤 모드

using System;
using System.Drawing;

- 주요 명령
- FileUpload.Hasfile : 파일 첨부되었는지 확인 
- FileUpload.saveAs() : 서버측 경로에 파일 저장 
- Fileupload.postFile.contentLength : 첨부 파일의 사이즈(Byte)
- 대용량 파일 업로드 하고 싶을 때 Configuation 파일 추가

 <system.web>
    <!--
            컴파일된 페이지에 디버깅 기호를 삽입하려면
            compilation debug="true"로 설정하십시오. 이렇게
            하면 성능에 영향을 주므로 개발하는 동안에만
            이 값을 true로 설정하십시오.
        -->대용량 파일 크기를 지정하여 준다....
    추가 : <httpRuntime maxRequestLength="2000000"/> 

public partial class _10월8일_FrmFileUpload : System.Web.UI.Page
{  
    protected void Button1_Click(object sender, EventArgs e)
    {
        //파일이 첨부되었는지 확인
        if (FileUpload1.HasFile)
        {
            //업로드 : 같은 경로의 files라는 폴더에 넘겨온 파일명(폴더명X)으로 저장
            FileUpload1.SaveAs(
                    Server.MapPath(".") + "
\\file\\" + FileUpload1.FileName);

            //다운로드 링크 만들기
            string down = String.Format("<a href='{0}{1}'>{1}</a>", "./file/",
                                FileUpload1.FileName);
            Label1.Text = "업로드 되었습니다 <hr />" + down + "<hr />"
                          + "파일사이즈 : " + 
          //첨부된 파일의 사이즈(Byte)
          FileUpload1.PostedFile.ContentLength.ToString();
        }
        else
        {
            Label1.ForeColor = Color.Red;
            Label1.Text = "파일을 첨부하세요";
        }
    }
}




반응형
posted by Magic_kit