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" wrote:
> 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
- - -
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
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"benoit" wrote:
> 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 DA
TA
> folder that I would like to retrieve
> anybody an idea
> thx
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
"Peter Bromberg [C# MVP]" wrote:
> Benoit,
> Server.MapPath(...) works starting at the IIS Virtual directory root of th
e
> 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
> --
> Co-founder, Eggheadcafe.com developer portal:
> http://www.eggheadcafe.com
> UnBlog:
> http://petesbloggerama.blogspot.com
>
>
> "benoit" wrote:
>
"benoit" wrote:
> 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 espaol : http://asp.net.do/foros/
===================================
"benoit" <benoit@.discussions.microsoft.com> wrote in message
news:DFDBDCA4-291C-437B-96C8-9C7DD43B7A18@.microsoft.com...
> 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
>
>
> "Peter Bromberg [C# MVP]" wrote:
>
I noticed that when i teste the app in the past the address
was http://localhost/MyApp/...
and now http://localhost:someport/MyApp
Does it have something to do with that?
"Juan T. Llibre" wrote:
> 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/
> ===================================
> "benoit" <benoit@.discussions.microsoft.com> wrote in message
> news:DFDBDCA4-291C-437B-96C8-9C7DD43B7A18@.microsoft.com...
>
>
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 th
e 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 espaol : http://asp.net.do/foros/
===================================
"benoit" <benoit@.discussions.microsoft.com> wrote in message
news:932A4245-78F3-403C-BCDE-CC1110C31B94@.microsoft.com...
>I noticed that when i teste the app in the past the address
> was http://localhost/MyApp/...
> and now http://localhost:someport/MyApp
> Does it have something to do with that?
> "Juan T. Llibre" wrote:
>
Tuesday, March 13, 2012
Server.mappath
Labels:
asp,
code,
error,
failed,
folder,
invalidoperationexception,
mappath,
messagesystem,
net,
retrieve,
servermappath,
serverserver,
write
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment