I want to delete old image when uploading new one with c# but I get
the process cannot access the file because it is being used by another process. error
public void DeleteExistImage(string imageName)
    {
        string path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/" + imageName);
        using (var stream = new FileStream(path, FileMode.Create))
        {
            stream.Dispose();
            System.IO.File.Delete(path);
        }
    }
 
    