|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
File.Exists?code exists in a file named FindFile.aspx which exists in C:\Inetpub\wwwroot\ASPX: <script runat="server"> Sub Page_Load(obj As Object, ea As EventArgs) Dim ioFileInfo As FileInfo ioFileInfo = New FileInfo(Server.MapPath("../../Form1.asp")) If (ioFileInfo.Exists) Then Response.Write("File Exists") Else Response.Write("File Doesnot Exist") End If End Sub </script> Now since FindFile.aspx exists in the folder C:\Inetpub\wwwroot\ASPX & the file I am searching for (Form1.asp) exists in C:\Inetpub, I have to move up by 2 folders which is why I have used ../ twice in Server.MapPath but ASP.NET generates the following error: Cannot use a leading .. to exit above the top directory. pointing to the Server.MapPath line. How do I detect the existence of Form1.asp in C:\Inetpub? Thanks, Arpan Hi,
Well the problem seems to be a security issue. The root of your application is probably C:\Inetpub\wwwroot\ASPX and it makes sense that the Application cannot go above it. If you want to go above then you need to use standard File / Directory methods from the System.IO namespace. If your ASPNET windows user has the proper right you should be able to do something like the following: Dim path As String = "C:\Inetpub\Form1.asp" If File.Exists(path) Then Response.Write("File Exists") Else Response.Write("File Doesnot Exist") End If I did not try the code, it's just to give you an idea. The bottom line is that it makes sense that the method Server.MapPath cannot go higher in the directory structure than its root. Server.MapPath is used to translate a virtual path to a physical folder. the physical folder C:\Inetpub\ does not map to any virtual folder, then it can't work. I hope this help you understanding the problem. Best, Francois Malgreve. Show quote "Arpan" <arpan***@hotmail.com> wrote in message news:1156752489.000854.14760@75g2000cwc.googlegroups.com... >A file named Form1.asp exists in the folder C:\Inetpub. The following > code exists in a file named FindFile.aspx which exists in > C:\Inetpub\wwwroot\ASPX: > > <script runat="server"> > Sub Page_Load(obj As Object, ea As EventArgs) > Dim ioFileInfo As FileInfo > > ioFileInfo = New FileInfo(Server.MapPath("../../Form1.asp")) > If (ioFileInfo.Exists) Then > Response.Write("File Exists") > Else > Response.Write("File Doesnot Exist") > End If > End Sub > </script> > > Now since FindFile.aspx exists in the folder C:\Inetpub\wwwroot\ASPX & > the file I am searching for (Form1.asp) exists in C:\Inetpub, I have to > move up by 2 folders which is why I have used ../ twice in > Server.MapPath but ASP.NET generates the following error: > > Cannot use a leading .. to exit above the top directory. > > pointing to the Server.MapPath line. How do I detect the existence of > Form1.asp in C:\Inetpub? > > Thanks, > > Arpan > When the "enable parent path" IIS setting is disabled (which is now the
default) .. is not usable in Server.MapPath for security reasons. Another option is to use Server.MapPath to get the base location first (or you could get the application root directly). Then you can alter this location yo get at whetever location you want.... -- Patrice "Arpan" <arpan***@hotmail.com> a écrit dans le message de news: 1156752489.000854.14***@75g2000cwc.googlegroups.com...Show quote >A file named Form1.asp exists in the folder C:\Inetpub. The following > code exists in a file named FindFile.aspx which exists in > C:\Inetpub\wwwroot\ASPX: > > <script runat="server"> > Sub Page_Load(obj As Object, ea As EventArgs) > Dim ioFileInfo As FileInfo > > ioFileInfo = New FileInfo(Server.MapPath("../../Form1.asp")) > If (ioFileInfo.Exists) Then > Response.Write("File Exists") > Else > Response.Write("File Doesnot Exist") > End If > End Sub > </script> > > Now since FindFile.aspx exists in the folder C:\Inetpub\wwwroot\ASPX & > the file I am searching for (Form1.asp) exists in C:\Inetpub, I have to > move up by 2 folders which is why I have used ../ twice in > Server.MapPath but ASP.NET generates the following error: > > Cannot use a leading .. to exit above the top directory. > > pointing to the Server.MapPath line. How do I detect the existence of > Form1.asp in C:\Inetpub? > > Thanks, > > Arpan > |
|||||||||||||||||||||||