gpt4 book ai didi

asp.net-mvc-4 - system.io.file.exists 在 mvc4 中不工作

转载 作者:行者123 更新时间:2023-12-02 07:30:11 25 4
gpt4 key购买 nike

我正在从剑道上传控件中删除图像。

这是我的代码

  public ActionResult Remove(string[] fileNames)
{

if (fileNames != null)
{
foreach (var fullName in fileNames)
{
var fileName = Path.GetFileName(fullName);
var physicalPath = Server.MapPath(Path.Combine(("~/AssetAttachments"),fileName));

if (System.IO.File.Exists(physicalPath))
{
System.IO.File.Delete(physicalPath);
}
}
}
return Content("");
}

我的物理路径是 E:\karthik related\JPL\Dev\Src\AssetTrackingSystem\AssetTrackingSystem\AssetAttachments\Attach3.jpg

即使文件和目录可用

  if (System.IO.File.Exists(physicalPath))

返回 false 并且不正常。

我们将不胜感激。

最佳答案

试试这个:

foreach (var fullName in fileNames)
{
var physicalPath = System.IO.Path.Combine(HttpContext.Current.Server.MapPath("~/AssetAttachments"), fullName);

if (System.IO.File.Exists(physicalPath))
{
System.IO.File.Delete(physicalPath);
}
}

关于asp.net-mvc-4 - system.io.file.exists 在 mvc4 中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22706104/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com