views:

101

answers:

1

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 path

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 http://stackoverflow.com/questions/1158530/asp-net-server-mappath-problem-from-inner-folders

+1  A: 

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);
geofflane