易截截图软件、单文件、免安装、纯绿色、仅160KB

C Sharp(C#)中如何删除文件(文件夹)

C Sharp(C#)中如何删除文件(文件夹)
直接删除:
using System.IO;
...
string filePath = @"D:\...\xxx.xxx";

if (File.Exists(filePath))
{
File.Delete(filePath);
}
else
{
Console.WriteLine("file not exist.");
Console.ReadLine();
}
删除到回收站:
using System.Runtime.InteropServices;
namespace CSharp
{
class Program
{
private const int FO_DELETE = 3;
private const int FOF_ALLOWUNDO = 0x40;
private const int FOF_NOCONFIRMATION = 0x0010;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 1)]
public struct SHFILEOPSTRUCT
{
public IntPtr hwnd;
[MarshalAs(UnmanagedType.U4)]
public int wFunc;
public string pfrom;
public string pTo;
public short fFlags;
[MarshalAs(UnmanagedType.Bool)]
public bool fAnyOperationsAborted;
public IntPtr hNameMappings;
public string lpszProgressTitle;
}
[DllImport("shell32.dll", CharSet = CharSet.Auto)]
static extern int SHFileOperation(ref SHFILEOPSTRUCT FileOp);
static void Main(string[] args)
{
string filePath = @"D:\...\xxx.xxx";

if (File.Exists(filePath))
{
SHFILEOPSTRUCT fileop = new SHFILEOPSTRUCT();
fileop.wFunc = FO_DELETE;
fileop.pfrom = filePath + '\0' + '\0';
fileop.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION;
SHFileOperation(ref fileop);
Console.WriteLine("delete ok");
Console.ReadLine();
}
else
{
Console.WriteLine("file not exist.");
Console.ReadLine();
}
}
}
}


相关文档:

C_使用switch语句

 源码:
# include <stdio.h>
 
int main()
{
    int num;
    /* 下面定义的各变量,分别代表个位,十位,百位,千位,万位,十万位以及位数 */
    int indiv, ten, hundred, thousand; 
    int ten_thousand, hundred_thous ......

C_使用while语句求两整数的最小公倍数与最大公约数

 源码:
# include <stdio.h>
 
int main()
{
    int x, y, num1, num2, temp;
    printf("请输入两个正整数:\n");
    scanf("%d %d", &num1, &num2);
 
    if(num1 < num2)
   ......

C_运用do

 源码:
# include <math.h>
# include <stdio.h>    /* 数学函数库 */
 
int main()
{
    /* 用s表示多项式的值,用t表示每一项的值 */
    double s, t, x; // 此处用双精度声明变量
    int n;
    printf ......

c# SQL数据库远程连接及配置方法

一:C# 连接SQL数据库
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;
Server=myServerAddress;Database=myDataBase;User ID=myUse ......

C#读取sqlserver 动画flash swf 文件到本地硬盘

 using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlC ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号