Solved

Invalid path for MapPath

Posted on 2006-07-11
8
804 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 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
 

Author Comment

by:SirReadAlot
ID: 17082474
will try this

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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 Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now