Solved

Invalid path for MapPath

Posted on 2006-07-11
8
812 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 35

Assisted Solution

by:mrichmon
mrichmon earned 250 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
Technology Partners: 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 250 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

Industry Leaders: 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!

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

729 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