简体   繁体   English

在JavaScript中获取本地系统中的文件路径

[英]Get File Path in local System in JavaScript

I am trying to get the client local path without hard coding in JavaScript. 我试图在不使用JavaScript进行硬编码的情况下获取客户端本地路径。 I used the below code to get the path, but it is retrieved from the server. 我使用下面的代码来获取路径,但是它是从服务器检索的。 Can someone help me how to get local file path in JavaScript. 有人可以帮助我如何在JavaScript中获取本地文件路径。

recordPath = System.IO.Path.GetDirectoryName(System.IO.Path.GetDirectoryName(
                                          HttpContext.Current.Server.MapPath("saveFile")));

You cannot get an absolute file path via javascript. 您无法通过javascript获取绝对文件路径。 You can only get file paths relative to the server page. 您只能获取相对于服务器页面的文件路径。

location.pathname;
location.hostname;

All absolute paths should be handled on the back end, and should not be hard coded into js, which is freely visible to the user. 所有绝对路径应在后端处理,并且不应硬编码为js,这对用户是免费的。

Javascript does not allow showing drive paths. Javascript不允许显示驱动器路径。 You can try vbScript for it. 您可以尝试使用vbScript。 Check This Out : 看一下这个 :

How to get Hard Disk number from drive letter using VBScript 如何使用VBScript从驱动器号获取硬盘号

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM