开发者

What is wrong with this file path?

开发者 https://www.devze.com 2022-12-16 05:01 出处:网络
Hai guys, I have two folders called CSVLoad and Forms... I have an aspx page inside forms folder which has a fileupload control. I save my uploaded file to my CSVLoad folder i gave the following p开发

Hai guys,

I have two folders called CSVLoad and Forms... I have an aspx page inside forms folder which has a fileupload control. I save my uploaded file to my CSVLoad folder i gave the following p开发者_StackOverflow中文版ath

FileUpload1.SaveAs(Server.MapPath("CSVLoad//" + FileUpload1.FileName));

I am receiving file not found exception...

Could not find a part of the path 
'F:\WebSites\Payroll\Forms\CSVLoad\Employeesdata.csv'

CSVLoad folder is outside Forms folder (ie) both are root level folders of my application

Answer :

FileUpload1.SaveAs(Server.MapPath("~/CSVLoad//" + FileUpload1.FileName));

from one of previous SO questions ASP.NET Server.Mappath problem from inner folders


If the path does not start with a slash, then it returns a path relative to the current directory that the page is in, in this case Forms I assume. If you want it to map a path relative to the root of your application, then you should prefix a slash on the path and use:

Server.MapPath("~/CSVLoad/" + FileUpload1.FileName);
0

精彩评论

暂无评论...
验证码 换一张
取 消