简体   繁体   English

C#可以按路径打开特定文件的容器文件夹吗?

[英]Can C# open a the container folder of a specific file by its path?

In my project, I have a fileupload control for user to upload their document and I want to provide a link to user to open their files. 在我的项目中,我有一个fileupload控件供用户上传其文档,并且我想提供一个指向用户的链接以打开其文件。

steps: after user upload a file, my web will create a link for it when user click on that link, the container folder of that file will open. 步骤:用户上传文件后,当用户单击该链接时,我的网站将为其创建链接,该文件的容器文件夹将打开。

For example, a file which its path is C:\\Users\\John\\Downloads\\jpg\\a.jpg uploaded to the fileupload control. 例如,路径为C:\\Users\\John\\Downloads\\jpg\\a.jpg上载到fileupload控件。 when user click on the link of that file, a folder C:\\Users\\John\\Downloads\\jpg will be opened. 当用户单击该文件的链接时,将打开一个文件夹C:\\Users\\John\\Downloads\\jpg

To get the file path: 获取文件路径:

string filePath = FileUpload1.PostedFile.FileName; // file name with path.

So, how can I open a folder in client PC by C#? 那么,如何通过C#在客户端PC中打开文件夹?

For security reasons, browsers do not expose the local filesystem to the Javascript sandbox . 出于安全原因, 浏览器不会将本地文件系统公开给Javascript沙箱 What you're asking is not possible with Javascript or any other common browser technology that does not require a client install (like Flash or ActiveX). Java或其他不需要客户端安装的常见浏览器技术(例如Flash或ActiveX)无法实现您的要求。 You definitely cannot get it in c# which runs on the server and has no knowledge of the client's filesystem. 您肯定无法在服务器上运行的c#中获取它,并且不了解客户端的文件系统。

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

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