Solved

Invalid path for MapPath

Posted on 2006-07-11
8
803 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 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

13 Experts available now in Live!

Get 1:1 Help Now