Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting to a network folder with FSO 1

Status
Not open for further replies.

snoopy75

Technical User
Aug 24, 2001
340
US
Hi all, I'm trying to iterate through files in a folder contained in a network share, using ASP. Here's my code:
Code:
Dim objFSO, objFolder, strFolder
Set objFSO = server.CreateObject("Scripting.FileSystemObject")
strFolder = "\\hif-fslgnt1\logon$\Tracking data\Logon\Users\" & (rsEmployees.Fields.Item("AliasName").Value) &  "\"
Set objFolder = objFSO.GetFolder(strFolder)
I get a "Path Not Found" error on the last line. I know the path exists, because I can response.write it, copy and paste it into Explorer, and it opens just fine on my machine. Is my syntax wrong, or is it not possible to connect to this network share for some reason? Thanks!
 
Hello snoopy75,

Webserver does not have access to network resources. Hence, to do it, you have to map the network share to some drive letter and the getfolder through the drive letter.

regards - tsuji
 
I see. I'm not certain that I have those kind of rights on the webserver, but how would I map a drive letter with ASP, just in case?
 
If you change the Anonymous user that the website that runs that script uses to a Domain User account with access to the folders and files you are trying to get to, you should be able to use FSO just fine.
 
I *know* they won't give me that kind of access, so I guess I'm stuck. I'll have to figure out another way to get to that data, I suppose. Thanks anyway.
 
Well if you don't have that kind of access, any chance of a user id on that box that has access? You could use Window Scripting Host and log in and map a drive
 
I am having the same problem as snoopy75... I do however have access to the IIS Server... Tried mapping the network location to a drive as well as setting up a virtual directory with IIS... I still get the following error..

"Microsfot VBScript runtime error '800a004c'
Path Not found

The line giving the error is...
Set objFolder = objFSO.GetFolder(server.mappath("/web_temp/"))

/webtemp/ is the virtual directory in IIS...

Anyone with any other ideas would be greatly appreciated...

-Matt
 
Is objFSO instantiated with Server.CreateObject ?
Is this code executed server side (ie inside <% .. %>) ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
This is what I have tried when connecting to a public share, but on W2K3/IIS6 I still get an error that reads "Object Required 'WScript'". I thought scripting host was installed by default on Windows 2003 server? Anyway, hopefully this gets us closer?
Code:
<%
'Create Drive Mapping
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive "U:", "\\myserver.domain.com\public"

dim fs,fo,x
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fo=fs.GetFolder("U:\")

for each x in fo.SubFolders
  'Print the name of all subfolders in the test folder
  Response.write(x.Name & "<br />")
next
set fo=nothing
set fs=nothing

'Remove Drive Mapping
WshNetwork.RemoveNetworkDrive "U:"  
%>
 

try changing:
Code:
WshNetwork.MapNetworkDrive "U:", "\\myserver.domain.com\public"

to:

Code:
WshNetwork.MapNetworkDrive "U:", "\\myserver.domain.com\public", "false", "myserver.domain.com\username", "password"
 
pkailas,

In my case it is a public share within our network security context, so no login/password is needed. However, your method would work if I needed to log in to a password protected share. Anyway, the failure is occurring at:

Set WshNetwork = WScript.CreateObject("WScript.Network")

Thanks,
Taz
 
oh, duh... ok, here's your error!

Change:
Code:
Set WshNetwork = WScript.CreateObject("WScript.Network")

to:
Code:
Set WshNetwork = Server.CreateObject("WScript.Network")
{/code]
 
or, leave off the wscript from the createobject.

What I gave you in the previous example was for ASP
 
Thanks! Removing WScript from WScript.CreateObject worked. Also, your suggestion regarding the login and password is a good one because of the context of the application. I use a generic web application user. The final code that worked is:

Code:
<%
'Create Drive Mapping
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive "U:", "\\myserver.domain.com\public", "false", "DOMAIN\username", "password"

dim fs,fo,x
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fo=fs.GetFolder("U:\")

for each x in fo.SubFolders
  'Print the name of all subfolders in the test folder
  Response.write(x.Name & "<br />")
next
set fo=nothing
set fs=nothing

'Remove Drive Mapping
WshNetwork.RemoveNetworkDrive "U:"  
%>
 
heh... your example above still has the WScript.CreateObject in it. does that work that way? Or did you just forget to remove it when you pasted it here?

Glad I could help!
 
Yes, sorry, I forgot to remove the WScript from the CreateObject call in the post above.

Thanks again,
Taz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top