2009-07-19 2 views
2

"~/Uploads/Images /"를 절대 경로로 변환하려고합니다. FileStream을 만들 수 있습니다. 나는 VirtualPathUtility와 Path.Combine을 시도했지만 아무것도 올바른 경로를 제공하지 않는 것 같습니다. 내가 얻은 가장 가까운 것은 VirtualPathUtility.ToAppRelative 였지만 그 파일의 위치는 C :의 직접적인 자식이었습니다.ASP.NET : 상대 경로가있는 Path.Combine

이렇게하는 방법이 있어야합니다.

+0

당신이 절대 경로 또는 절대 URL을 원하십니까 :

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

는 파일 경로를 만들 Path.Combine와 함께 사용? – tvanfosson

답변

8

MapPath 방법을 찾고 있습니다.

string fileName = Path.Combine(
         HttpContext.Current.Server.MapPath("~/Uploads/Images/"), 
         "filename.ext"); 
using (FileStream stream = File.OpenRead(fileName)) 
{ 
    // read the file 
} 
+0

정말 고마워. – Echilon

관련 문제