Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Server.MapPath - Physical path given, virtual path expected

Tags:

c#

asp.net

I'm using this line of code:

var files = Directory.GetFiles(Server.MapPath("E:\\ftproot\\sales")); 

to locate files in a folder however I get the error message saying that

"Physical Path given but virtual path expected".

Am new enough to using System.IO in C# so I was wondering if it's possible to enter a physical path to do this?

like image 747
109221793 Avatar asked Feb 18 '11 09:02

109221793


People also ask

Is a physical path but a virtual path was expected Server MapPath?

Generally this physical and virtual path problem occurred whenever we refer “Server. MapPath” value multiple times while using folder path in applications. To solve this e:is a physical path but a virtual path was expected we need to use Server.

What is virtual path and physical path?

First of all, let's get the overview of both. Physical path - This is the actual path the file is located by IIS. Virtual path - This is the logical path to access the file which is pointed to from outside of the IIS application folder.

How does server MapPath work?

If path is null , the MapPath method returns the full physical path of the directory that contains the current request for the path. The relative path does not need to specify an existing file or folder for this method to return a value. However, you cannot specify a path outside of the Web application.

What is Server MapPath in MVC?

For example, Server. MapPath() allows a path of "files/file1. doc". It uses the current context to determine the path of the current page, for example, and then creates the relative path from there.


1 Answers

if you already know your folder is: E:\ftproot\sales then you do not need to use Server.MapPath, this last one is needed if you only have a relative virtual path like ~/folder/folder1 and you want to know the real path in the disk...

like image 60
Davide Piras Avatar answered Sep 20 '22 11:09

Davide Piras