佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 981|回复: 1

求asp.net c# 删除文件代码

[复制链接]
发表于 16-1-2013 01:09 PM | 显示全部楼层 |阅读模式
Directory.Delete 可以删除文件吗?为什么我只能删除 folder , file却不行  ?

file 不行!
  string target = @"d:\TestDir\1.jpg";
        try
        {
            if (Directory.Exists(target))
            {
                Directory.Delete(target, true);
            }
        }
        catch (Exception ex)
        {
            string a = "";
            a = ex.Message;
        }
folder 可以!
  string target = @"d:\TestDir";
        try
        {
            if (Directory.Exists(target))
            {
                Directory.Delete(target, true);
            }
        }
        catch (Exception ex)
        {
            string a = "";
            a = ex.Message;
        }

回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 16-1-2013 01:49 PM | 显示全部楼层
问题解决
delete file 要用
string target = @"d:\TestDir\1.jpg";
        try
        {
            if (File.Exists(target))
            {
                File.Delete(target);
            }
        }

        catch (Exception ex)
        {
            string a = "";
            a = ex.Message;
        }
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 6-10-2025 01:26 PM , Processed in 0.121898 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表