'Server.MapPath'에 해당되는 글 1건

  1. 2009.05.21 HttpFileCollection 을 사용한 다중 파일 업로드

HttpFileCollection 을 사용한 다중 파일 업로드

.Net 2009. 5. 21. 15:57 posted by 무명시인
사용자 삽입 이미지

이렇게 여러게의 파일컴포넌트가 있다면;;

머 각기 파일 존대 여부를 체크하여 파일을 업로드 하여도 상관은 없다..

하지만..

이왕이면 코드를 줄여보자..

이렇게

 HttpFileCollection file = Request.Files;

        for (int i = 0; i < file.Count; i++)
        {
            if (file[i].ContentLength > 0)
            {
                HttpPostedFile postedFile = file[i];
                string strPath = String.Format("{0}\\{1}", Server.MapPath("~/Files"), System.IO.Path.GetFileName(postedFile.FileName));                
                postedFile.SaveAs(strPath);
            }            
         
}
사용자 삽입 이미지


이런 코드를 사용하여 유저컨트롤이나 사용자 정의 컨트롤로 멀티 업로드 컴포넌트를 만들어 사용해도 무관하겠다.