Access network shares with filesystemobject

J

Josh Rolfe

I have a page in classic asp that accces a network drive, The code is as
follows:
<%
dim fso
dim objFolder
set fso=server.createObject("Scripting.FileSystemObject")
set objFolder=fso.GetFolder("f:\")
for each objFile in objFolder.files
response.write objFile.name & "<br>"
next
%>

(f: is a network drive)
I am trying to do the same thing in asp.net. My code behind is as follows:

Public Class WebForm1
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

....

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim fso, objFolder, objFile As Object
Dim strFolder As String
fso = Server.CreateObject("Scripting.FileSystemObject")
strFolder = "f:\"
objFolder = fso.getFolder(strFolder)
For Each objFile In objFolder.files
Response.Write(objFile.name & "<br>")
Next
End Sub
End Class

Both pages run as integrated authentication with no anonymous access
allowed. it works fine in classic asp, but not in asp.net. It works in
asp.net if I access a local folder like c:\. The error I get in asp.net is:

Exception from HRESULT: 0x800A004C (CTL_E_PATHNOTFOUND).
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.IO.DirectoryNotFoundException: Exception from
HRESULT: 0x800A004C (CTL_E_PATHNOTFOUND).
 
C

Clamps

You could use the UNC instead.
io.file.exists(\\server\sharedfolder) instead of mapped drive letter.
 
J

Josh Rolfe

Doing gives the same results - I cannot access network shares with UNC
either (although this also works fine in class asp)
 
J

Juan T. Llibre

B

Bruce Barker

asp runs pages with the iis authentication account defined for anonymous.
you proably specified a domain account.

asp.net runs as the asp.net account no matter the iis creditals. tell
asp.net to use the iis creditials by setting <Identity Impersonate=true> in
the web config. still must setup a domain account for anonymous.

-- bruce (sqlwork.com)
 
B

Ben

I don't know if any of this helps...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetch08.asp
Accessing Files on a UNC File Share
If your application needs to access files on a Universal Naming Convention
(UNC) share using ASP.NET, it is important to add NTFS permissions to the
share's folder. You will also need to set the share's permissions to grant
at least read access to either the ASP.NET process account or the
impersonated identity (if your application is configured for impersonation).



http://www.dotnetjunkies.net/Forums/ShowPost.aspx?PostID=1531
http://west-wind.com/weblog/posts/1572.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top