上传图片后如何删除图片?

时间:2019-06-19 08:39:39

标签: asp.net asp.net-mvc asp.net-core

嗨,我使用此代码将图像上传到驱动器中

public static string SaveImage(this IFormFile imageFile, string fileName, string path)
    {
        if (string.IsNullOrEmpty(fileName))
            fileName = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(imageFile.FileName);
        path = Path.Combine(Directory.GetCurrentDirectory(), path, fileName);
        using (var stream = new FileStream(path, FileMode.Create))
        {
            imageFile.CopyTo(stream);
        }
        return fileName;
    }

然后上传并使用此代码单击删除

public static void DeleteImage(this string fileName, string path)
    {
        string imgPath = Path.Combine(Directory.GetCurrentDirectory(), path, fileName);
        if (System.IO.File.Exists(imgPath))
        {
            System.IO.File.Delete(imgPath);
        }
    }

说使用另一个过程? 我无法删除

0 个答案:

没有答案