coding

HostingEnvironment.MapPath(String)와 Server.MapPath("~")

사과키라임파이 2022. 5. 2. 10:40

 string uploadpath = HostingEnvironment.MapPath(directory);

 string uploadpath = HttpContext.Current.Server.MapPath("~") + directory;

D:\\00_SCK_azure\\220427 대용량 파일 삽입 시간\\insertProjectXlsxAndCSV\\insertProject\\UploadFiles\\Sample\\"

 

HostingEnvironment.MapPath(String)과 Server.MapPath("~")은 같은 결과를 보임.

HttpContext.Current.Server.MapPath = Server.MapPath("~")

 

HostingEnvironment.MapPath(String) 메서드

가상 경로, 혹은 상대경로를 서버의 실제 경로에 매핑

매개 변수

virtualPathString

가상 경로(절대 또는 상대)입니다.

 

 

var filename = Path.Combine(uploadpath, file.FileName);

 

 

만약 해당 위치의 절대경로에 폴더가 없다면? 폴더를 만들어줌.

if (!Directory.Exists(절대경로))
                {
                    // 지정된 경로에 폴더 만들기
                    Directory.CreateDirectory(절대경로);
                }

}