愚蠢的问题,但这里......
是否可以编写使用 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。
有任何想法吗?