Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Invalid path for MapPath

Posted on 2006-07-11
8
Medium Priority
?
818 Views
Last Modified: 2012-05-05
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.
0
Comment
Question by:SirReadAlot
  • 5
  • 2
8 Comments
 
LVL 35

Assisted Solution

by:mrichmon
mrichmon earned 1000 total points
ID: 17082357
Server.MapPath usually is used to turn a virtual path i.e. /Files to the physical equivalent i.e. C:\Inetpub\wwwroot\AutoDataCaputure_2\Files\

If you already have the physical path why are you using MapPath?

If not can you show the actual lines of code being used and what you are trying to do.
0
 

Author Comment

by:SirReadAlot
ID: 17082385

{
                  
                        //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
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 17082447
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));
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:SirReadAlot
ID: 17082474
will try this

0
 

Author Comment

by:SirReadAlot
ID: 17082518
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".
0
 
LVL 3

Accepted Solution

by:
BBK_ earned 1000 total points
ID: 17082529


Basically “Mappath” maps a specified path to a physical path.
In your case, you know the physical path, rather you want to get the virtual path.
For that case you cannot use this method

I think you are looking for the method “GetAppPath” in HttpWorkerRequest class

Cheers
Bijith

0
 

Author Comment

by:SirReadAlot
ID: 17082533
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\"");                              
                 
            
0
 

Author Comment

by:SirReadAlot
ID: 17082538
I think you are looking for the method “GetAppPath” in HttpWorkerRequest class


ok will try anything
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Screencast - Getting to Know the Pipeline

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question