Server.mappath

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

if I write this code to retrieve a folder on the server
Server.mappath("/DATA")

I get this error message
System.InvalidOperationException: Failed to map the path '/DATA'

the virtual folder for my webApp is not situated in Inetpub, nor is the DATA
folder that I would like to retrieve

anybody an idea

thx
 
Benoit,
Server.MapPath(...) works starting at the IIS Virtual directory root of the
currently running application page.
It does not work for folders anywhere outside the IIS Vroot of the current
application.

What is it that you are trying to accomplish?
Peter
 
benoit said:
if I write this code to retrieve a folder on the server
Server.mappath("/DATA")

I get this error message
System.InvalidOperationException: Failed to map the path '/DATA'

the virtual folder for my webApp is not situated in Inetpub, nor is the
DATA
folder that I would like to retrieve

I doesn't need to be in Inetpub.

Is "data" the name of a folder inside your webapp? If so, shouldn't your
line read Server.mappath("/WebApp/Data") ?

Steven

- - -
 
Well

On ASP.NET 1.1 I had two webapps on the same server
/WNW
and
/Data

/Data was a virtual folder in which images and Xml are stored.
With Server.MapPath("/Data") i could without any problem read my Xml and
images.
Since I made the move to ASP.Net 2.0, I am no longer able to retrieve my
data the way I used to
 
benoit said:
On ASP.NET 1.1 I had two webapps on the same server
/WNW
and
/Data

/Data was a virtual folder in which images and Xml are stored.
With Server.MapPath("/Data") i could without any problem read my Xml and
images.
Since I made the move to ASP.Net 2.0, I am no longer able to retrieve my
data the way I used to

IIRC, this is a security issue. What about putting a virtual dir in /WNW
called "Data" that points to the same location as /Data? That way you can
use Server.MapPath("/WNW/Data");

Steven

- - -
 
That's strange.

I can retrieve physical paths by using Server.MapPath("/virtualDir")
without any problem.

mappath.aspx:
----------------
<%@ Page Language="VB" %>
<script language = "VB" runat = "server">
Sub Page_Load(ByVal obj As Object, ByVal e As EventArgs)
Dim x As String = Server.MapPath("/SomeApp")
Label1.Text = "The physical directory for /SomeApp is : " & x
End Sub
</script>
<html>
<head runat="server">
<title>Server.MapPath</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server"></asp:Label><br/>
</div>
</form>
</body>
</html>
----------------



Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
 
re:
Does it have something to do with that?

Server.MapPath returns the correct physical directory regardless of whether
you use the built-in server in the VS IDE, or whether you use IIS to view the page.

All it needs is a valid relative URL ( a virtual path ).



Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
 
Back
Top