2010-05-12 156 views
0

我使用此代码来访问文件和文件夹:ASP文件系统对象不能访问共享服务器路径吗?

<%@ Language=VBScript %><% 
option explicit 
dim sRoot, sDir, sParent, objFSO, objFolder, objFile, objSubFolder, sSize 
%> 
<META content="Microsoft Visual Studio 6.0" name=GENERATOR><!-- Author: Adrian Forbes --> 
<% 

sRoot = "D:Raghu" 
sDir = Request("Dir") 
sDir = sDir & "\" 

Response.Write "<h1>" & sDir & "</h1>" & vbCRLF 

Set objFSO = CreateObject("Scripting.FileSystemObject") 
on error resume next 

Set objFolder = objFSO.GetFolder(sRoot & sDir) 
if err.number <> 0 then 
    Response.Write "Could not open folder" 
    Response.End 
end if 
on error goto 0 

sParent = objFSO.GetParentFolderName(objFolder.Path) 

' Remove the contents of sRoot from the front. This gives us the parent 
' path relative to the root folder 
' eg. if parent folder is "c:webfilessubfolder1subfolder2" then we just want "subfolder1subfolder2" 
sParent = mid(sParent, len(sRoot) + 1) 

Response.Write "<table border=""1"">" 

' Give a link to the parent folder. This is just a link to this page only pssing in 
' the new folder as a parameter 
Response.Write "<tr><td colspan=3><a href=""browse.asp?dir=" & Server.URLEncode(sParent) & """>Parent folder</a></td></tr>" & vbCRLF 

' Now we want to loop through the subfolders in this folder 
For Each objSubFolder In objFolder.SubFolders 
    ' And provide a link to them 
    Response.Write "<tr><td colspan=3><a href=""browse.asp?dir=" & Server.URLEncode(sDir & objSubFolder.Name) & """>" & objSubFolder.Name & "</a></td></tr>" & vbCRLF 
Next 

' Now we want to loop through the files in this folder 
For Each objFile In objFolder.Files 
    if Clng(objFile.Size) < 1024 then 
     sSize = objFile.Size & " bytes" 
    else 
     sSize = Clng(objFile.Size/1024) & " KB"  
    end if 
    ' And provide a link to view them. This is a link to show.asp passing in the directory and the file 
    ' as parameters 
    Response.Write "<tr><td><a href=""show.asp?file=" & server.URLEncode(objFile.Name) & "&dir=" & server.URLEncode (sDir) & """>" & objFile.Name & "</a></td><td>" & sSize & "</td><td>" & objFile.Type & "</td></tr>" & vbCRLF 
Next 

Response.Write "</table>" 
%> 

它工作正常。但是当我尝试访问像"\\cvrdd0110:share"这样的共享路径时,会出现错误。如何访问这些文件?抱歉格式问题。

回答

2

权限问题。请参阅this kb(适用于IIS 4/5; IIS 6/7可能需要不同的方法)。