Link to home
Start Free TrialLog in
Avatar of SirReadAlot
SirReadAlot

asked on

Invalid path for MapPath

Hi experts,

My application is trying to get to this path but it comes up with this error,

Does anyone know a work round?

thanks

Invalid path for MapPath 'C:\Inetpub\wwwroot\AutoDataCaputure_2\Files\'. A virtual path is expected.
SOLUTION
Avatar of mrichmon
mrichmon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SirReadAlot
SirReadAlot

ASKER


{
                  
                        //if (postedFile != null && postedFile.FileName.Length > 0 && this.ddEmployers.SelectedValue.Length > 0 && this.ddEmployers.SelectedValue != "Click to select a client from the list")
                  
                       if(!checkEmployer())
                        {
                              lblErrorReport.Text = "Employer ID already exists in the Database.";
                        }
                        else
                        {
                            this.lblErrorReport.Text = "";
                              this.lblfilename.Text = Path.GetFileName(postedFile.FileName);
//                              postedFile.SaveAs("C:\\code\\" + Path.GetFileName(postedFile.FileName));

                              
                              
                              postedFile.SaveAs(HttpContext.Current.Server.MapPath("C:\\Inetpub\\wwwroot\\AutoDataCaputure_2\\Files\\")+ Path.GetFileName(postedFile.FileName));
                              
                  thanks
Change this:

postedFile.SaveAs(HttpContext.Current.Server.MapPath("C:\\Inetpub\\wwwroot\\AutoDataCaputure_2\\Files\\")+ Path.GetFileName(postedFile.FileName));

to the web path where you want the file saved.  For example, assuming that wwwroot is the main root of the website and the others are directories then use:

postedFile.SaveAs(HttpContext.Current.Server.MapPath("/AutoDataCaputure_2/Files/")+ Path.GetFileName(postedFile.FileName));
will try this

hi it now says  that it can't find the path to the file which I an browsing to!!

the file is there so the path to it is right
Could not find a part of the path "c:\inetpub\wwwroot\AutoDataCaputure_2\Files\Nykbulkship.xls".
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
postedFile.SaveAs(HttpContext.Current.Server.MapPath("/AutoDataCaputure_2/Files/")+ Path.GetFileName(postedFile.FileName));

                              //postedFile.SaveAs(HttpContext.Current.Server.MapPath("\\AutoDataCaputure_2\\Files\\")+ Path.GetFileName(postedFile.FileName));
                              
                              if (postedFile.ContentType == "application/vnd.ms-excel")
                              {
                                    
                                    conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + HttpContext.Current.Server.MapPath("/AutoDataCaputure_2/Files/") + Path.GetFileName(postedFile.FileName) +";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\"");                              
                 
            
I think you are looking for the method “GetAppPath” in HttpWorkerRequest class


ok will try anything