문제

"~/uploads/images/"를 절대 경로로 변환하려고합니다. 나는 가상 경로와 path.combine을 시도했지만 올바른 길을주는 것은 아무것도없는 것 같습니다. 내가 얻은 가장 가까운 것은 가상 Pathutility.toprelative였습니다. 그러나 그것은 C :의 직접 자녀로서 파일의 위치 일뿐입니다.

이를 수행하는 방법이 있어야합니다.

도움이 되었습니까?

해결책

당신은 찾고 있습니다 MapPath 방법.

// get the path in the local file system that corresponds to ~/Uploads/Images
string localPath = HttpContext.Current.Server.MapPath("~/Uploads/Images/");

Path.comBine과 함께 사용하여 파일 경로를 만듭니다.

string fileName = Path.Combine(
                      HttpContext.Current.Server.MapPath("~/Uploads/Images/"),
                      "filename.ext");
using (FileStream stream = File.OpenRead(fileName))
{
   // read the file
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top