c# - 如何从 asp.net mvc 3 应用程序中的 App_Data 文件夹中删除文件?

标签 c# asp.net-mvc c#-4.0 file-upload

我使用

从用户那里读取了一个 Excel 文件
 <input type="file" name="file" />

发送到 Controller 并存储在App_Data文件夹中。我读了那个文件。完成后,我希望从 App_Data 文件夹中删除该文件。我怎么做? 这就是我存储它的方式。

    public ActionResult importFile1(HttpPostedFileBase file)
    {

        if (file != null && file.ContentLength > 0)
        {
            // extract only the fielname
            var fileName = Path.GetFileName(file.FileName);
            // store the file inside ~/App_Data/uploads folder
            var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
            file.SaveAs(path);
        }
    }

最佳答案

您尝试过使用

File.Delete("~/App_Data/uploads/myfile.xls");

文件处理完成后?

关于c# - 如何从 asp.net mvc 3 应用程序中的 App_Data 文件夹中删除文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20948311/

相关文章:

c# - 如何在 ASP.NET Core Angular Web 应用程序中调用 Controller 的操作

c# - System.Messaging.dll 在 .Net Core 中不可用吗?

C# 设置。 appdata的路径是如何确定的?

c# - 如何在管理 MVC 4 应用程序中重用模型和 View 进行添加和编辑

azure - 使用 DevelopmentStorage 的 CloudStorageAccount 凭据

c# - 为什么包含对 B 类型对象的引用的 A 类型引用变量不能访问 B 类的成员函数?

c# - 媒体捕捉 : Photos have odd color letterboxing on Windows Phone

c# - 如何为特定路由 Asp.Net MVC 构造我的操作方法

c# - 将名为 'other' 的项目保留在我的订购列表的底部

mysql - 通过 Entity Framework 获取 MYSQL UTC_TIMESTAMP