0

愚蠢的问题,但这里......

是否可以编写使用 File.Move 重命名用户计算机上的文件的 Intranet windows auth asp.net mvc 应用程序?或者 File.Move 和使用 Path.GetDirectory 和其他 System.IO 函数会查看 IIS 服务器目录结构而不是客户端计算机吗?

    [HttpPost]
    public ActionResult Index(HttpPostedFileBase file, string append)
    {
        try
        {
            if (file != null && file.ContentLength > 0)
            {
                var fileName = Path.GetFileName(file.FileName);
                DirectoryInfo filepath = new DirectoryInfo(file.FileName);
                string parentpath = Path.GetDirectoryName(filepath.FullName);
                DirectoryInfo searchablePath = new DirectoryInfo(parentpath);

                var directories = searchablePath.GetFiles("*", SearchOption.AllDirectories);

                foreach (FileInfo d in directories)
                {
                    if (!string.IsNullOrEmpty(append) && !d.Name.Contains(append))
                    {
                        string fName = Path.GetFileNameWithoutExtension(d.Name);
                        string fExt = Path.GetExtension(d.Name);

                        System.IO.File.Move(d.FullName, Path.Combine(d.DirectoryName, fName + append + fExt));
                    }
                }
            }
        }
        catch (Exception ex)
        {

        }

        return View();
    }

我已经尝试过了,但我得到了一个 filenotfoundexception。

有任何想法吗?

4

2 回答 2

1

ASP.NET 代码在服务器上运行,因此它将查看服务器上的文件。

您无法重命名客户端计算机上的文件,但可以用作客户端的计算机上重命名文件,如果:

  • 服务器和计算机在同一个网络上
  • 服务器知道计算机的名称
  • 服务器知道在计算机中查找哪个文件夹
  • 该文件夹与在服务器上运行 ASP.NET 代码的用户帐户共享,该用户帐户具有更改文件名的足够权限

从这个意义上说,计算机不是服务器的客户端,但服务器通过文件系统直接与计算机通信,而不是通过 IIS。

于 2013-07-30T16:04:52.120 回答
0

这些确实只能在服务器上工作。

您可以查看用户浏览器提供的客户端 javascript API 的各种文件和文件系统相关规范:

于 2013-07-30T15:59:39.617 回答