admin管理员组文章数量:1289845
Is it possible for a webpage to popup a open folder dialog, ask the user to select a folder, then show the contents of that folder in a list(or something) in the webpage. It won't write to the files, only read them. The webpage is hosted remotely.
Jonathan
Is it possible for a webpage to popup a open folder dialog, ask the user to select a folder, then show the contents of that folder in a list(or something) in the webpage. It won't write to the files, only read them. The webpage is hosted remotely.
Jonathan
Share Improve this question edited Apr 25, 2010 at 20:13 skaffman 404k96 gold badges824 silver badges775 bronze badges asked Mar 21, 2010 at 8:43 Jonathan.Jonathan. 55.6k55 gold badges197 silver badges300 bronze badges 1- Which browsers do you want to support? JavaScript does not provide any standardized means for accessing the file system. (And that's on purpose, for security reasons. You wouldn't want any odd website to be able to browse around in your files, would you?). However, there are browser-specific ways to get to the file system (e.g. via an ActiveX object with IE). – stakx - no longer contributing Commented Apr 13, 2010 at 18:00
6 Answers
Reset to default 5In a word... No.
Requiring an ActiveX plug-in for your application is an invitation to utter failure. Unless you are writing a very target-specific app for an intranet where you control the client configuration, this is just a horrible idea.
There are strict limitations on what a web-based application can do, and this is one of them. What are you trying to acplish? Perhaps there's a way to do it with a standard file upload dialog? Or WebDAV?
I wrote this small piece of code that shows a list of files given a folder name. It is written using VBScript so will work only on IE and FireFox(and maybe only on windows). But it is worth a look
<HTML>
<HEAD>
<SCRIPT LANGUAGE='VBSCRIPT'>
Sub showfiles()
On Error Resume Next
Dim fso, folder, files, sFolder, path
Set fso = CreateObject("Scripting.FileSystemObject")
sFolder = Document.getElementById("fdr").value
Set folder = fso.GetFolder(sFolder)
Set files = folder.Files
For each folderIdx In files
mydiv.innerhtml=mydiv.innerhtml & "<BR/> " & folderIdx.Name
Next
end sub
</SCRIPT>
</HEAD>
<BODY>
<INPUT id="fdr" TYPE="TEXT" VALUE="C:\" />
<INPUT TYPE="BUTTON" ONCLICK="showfiles()" value="show files" />
<DIV id="mydiv"></DIV>
</BODY>
</HTML>
You can use a Signed Java Applet, it is a fairly mon solution. It works across browsers and platforms. All the user would have to do accept your certificate once and have the java runtime installed.
Alternatively you can write a browser plugin.
It'll make you (or your usesr) jump through a thousand hoops, but the ActiveX File System Object can possibly be used to do what you want...
http://msdn.microsoft./en-us/library/bkx696eh%28VS.85%29.aspx
edit -- added "possibly"
Edited :- Have a look at this. May be a workaround.
There is no way to do it with JavaScript, as it has no way of working with the operating system.
There is, however, a way to do it with VBScript (ASP.NET), but IE will throw a security warning to the user before allowing the code to execute only if their security level is less than Medium-Low.
If you're trying to access local files over the Internet, your best bet (outside of finding a vulnerability and getting access that way, i.e. the bad way) is by using Java or Flash.
If you still want the code (for ASP/VBscript):
Dim FileSystem
Set FileSystem = GetObject("Scripting.FileSystemObject")
If Err.Number <> 0 Then
MsgBox("Error setting FileSystem object; check WSH version.")
WScript.Quit(0)
End If
Dim Folder
Set Folder = FileSystem.GetFolder("folder_name")
If Err.Number <> 0 Then
MsgBox("Error getting folder.")
WScript.Quit(1)
End If
-Carlos Nunez
本文标签: Get contents of local folder in javascript (or ASPNET VB)Stack Overflow
版权声明:本文标题:Get contents of local folder in javascript (or ASP.NET VB) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741469451a2380512.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论