-
C# FileInfo获取文件的各种属性
C# 创建FileInfo对象,获取文件的各种属性,可以获取到以下的文件信息:创建时间、上次访问时间、上次写入时间、文件名称、完整目录、完整路径、是否只读、文件长度。
具体的实现过程:
textBox1.Text = openFileDialog1.FileName;
FileInfo finfo = new FileInfo(textBox1.Text); //实例化FileInfo对象
string strCTime, strLATime, strLWTime, strName, strFName, strDName, strISRead;
long lgLength;
strCTime = finfo.CreationTime.ToShortDateString(); //获取文件创建时间
strLATime = finfo.LastAccessTime.ToShortDateString(); //获取上次访问该文件的时间
strLWTime = finfo.LastWriteTime.ToShortDateString(); //获取上次写入文件的时间
strName = finfo.Name; //获取文件名称
strFName = finfo.FullName;//获取文件的完整目录
strDName = finfo.DirectoryName;//获取文件的完整路径
strISRead = finfo.IsReadOnly.ToString(); //获取文件是否只读
lgLength = finfo.Length; //获取文件长度
MessageBox.Show("文件信息:
创建时间:" + strCTime + " 上次访问时间:" + strLATime + "
上次写入时间:" + strLWTime + " 文件名称:" + strName + "
完整目录:" + strFName + "
完整路径:" + strDName + "
是否只读:" + strISRead + " 文件长度:" + lgLength);
以上代码段请写入一个按钮事件中,这样当用户单击按钮时,执行上述代码。
- 2023-02-14 12:35:03下载
- 积分:1
-
TMS320C6748各个接口外设所有标准源码程序 (亲测好使)
TMS320C6748各个接口外设所有标准源码程序 (亲测好使)
- 2022-07-16 14:39:18下载
- 积分:1
-
7Zip
This file is part of SevenZipSharp. SevenZipSharp is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. SevenZipSharp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with SevenZipSharp. If not, see .
- 2022-07-20 00:09:31下载
- 积分:1
-
C# 建立SQL Server数据库连接的基本方法
C# 建立SQL Server数据库连接的基本方法,核心代码为:
try
{
string ConStr =//创建数据库连接字符串
@"server=WIN-GI7E47AND9RLS;user id=sa;pwd=;database=db_TomeTwo";
SqlConnection con = new SqlConnection(ConStr);//创建数据库连接对象
string SqlStr = "select * from 帐单";//创建SQL查询字符串
SqlDataAdapter ada = new SqlDataAdapter(SqlStr, con);//创建数据适配器对象
DataSet ds = new DataSet();//创建数据表
ada.Fill(ds);//填充数据集
this.dgv_Message.DataSource =//设置数据源
ds.Tables[0].DefaultView;
}
catch(Exception ex)//捕获异常
{
MessageBox.Show(ex.Message,"提示!");//弹出消息对话框
}
- 2022-07-28 04:06:36下载
- 积分:1
-
用C#实现启动欢迎画面
用C#制作软件启动时的欢迎界面,开始画面,在软件被打开时最先显示的一个窗口效果,在本例中是直接调用一张图片来显示,但是具体的实现,比如图片显示的位置 、显示的时间长短等,用到的定时器,需要控制好,本实例代码就是向大家展示如何进行这些控制,部分代码为:
private void Form1_Load(object sender, EventArgs e)
{//启动窗体
Form2 MySplashForm = new Form2();
MySplashForm.ShowDialog();
}
private void Form2_Load(object sender, EventArgs e)
{//设置启动窗体
this.FormBorderStyle = FormBorderStyle.None;
this.BackgroundImage = Image.FromFile("test.jpg");
this.timer1.Start();
this.timer1.Interval = 10000;
}
private void timer1_Tick(object sender, EventArgs e)
{//关闭启动窗体
this.Close();
}
定时器控制:
private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{//关闭定时器
this.timer1.Stop();
}
- 2022-01-22 15:57:51下载
- 积分:1
-
C# jsapi微信支付源码
C# 微信jsapi支付源码,微信支付实例,编译生成的DLL程序与ASP.NET相结合,实现微信的ISAPI支付功能,需要服务器启用ASP.NET环境,一般是安装有微软的.NET Framework框架4.5以上版本。
- 2023-04-03 00:20:04下载
- 积分:1
-
C# 制作勤劳的小闹钟
C# 制作勤劳的小闹钟,将时间信息显示在textBox文本框中,textBox1.Text = DateTime.Now.ToString("HH时mm分ss秒");//在TextBox控件中显示系统时间。最终的运行效果如测试运行图所示,比较简单的小闹钟,C#新手参考。时间字体样式在代码中可以自定义,不喜欢这种时钟字体的,就自己修改吧。
- 2022-06-13 03:03:05下载
- 积分:1
-
C# 禁止鼠标左键单击的实现源码
C# 禁止鼠标左键单击,附上例子源码,禁止后将不响应鼠标左键消息,当然也可恢复鼠标左键,直接关闭本程序即可恢复,实现方法也很简单,看如下代码:
private void button1_Click(object sender, EventArgs e)
{//禁止鼠标左键单击
Application.AddMessageFilter(this);
MessageBox.Show("鼠标左键已经被禁止,请用Tab键执行操作!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void button2_Click(object sender, EventArgs e)
{//允许鼠标左键单击
Application.RemoveMessageFilter(this);
MessageBox.Show("鼠标左键已经被解禁,可以执行操作!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
public bool PreFilterMessage(ref System.Windows.Forms.Message MySystemMessage)
{//不响应鼠标左键消息
if (MySystemMessage.Msg >= 513 && MySystemMessage.Msg
- 2022-03-09 09:45:43下载
- 积分:1
-
C#监测服务运行源码
C#监测服务运行源码,监测服务的运行,且服务重启时会给相应用户发邮件
- 2022-01-26 04:33:30下载
- 积分:1
-
C# 创建有参、无参数等多线程操作实例
C# 多线程操作实例,获取指定进程的进程详细信息、获取指定进程的模块详细信息、创建无参数的多线程应用程序、创建带参数的多线程应用程序、创建共享线程模拟资源共享、创建子线程更新主线程数据等,部分代码分享如下:
if (MyThread.ThreadState == ThreadState.Terminated)
MyData += "
当前状态:已完成执行并已退出";
if (MyThread.ThreadState == ThreadState.Transition)
MyData += "
当前状态:在可以执行前等待处理器之外的资源";
if (MyThread.ThreadState == ThreadState.Unknown)
MyData += "
当前状态:状态未知";
if (MyThread.ThreadState == ThreadState.Wait)
MyData += "
当前状态:正在等待外围操作完成或等待资源释放";
if (MyThread.WaitReason == ThreadWaitReason.EventPairHigh)
MyData += "
等待原因:线程正在等待事件对高";
if (MyThread.WaitReason == ThreadWaitReason.EventPairLow)
MyData += "
等待原因:线程正在等待事件对低";
if (MyThread.WaitReason == ThreadWaitReason.ExecutionDelay)
MyData += "
等待原因:线程执行延迟";
if (MyThread.WaitReason == ThreadWaitReason.Executive)
MyData += "
等待原因:线程正在等待计划程序";
if (MyThread.WaitReason == ThreadWaitReason.FreePage)
MyData += "
等待原因:线程正在等待可用的虚拟内存页";
if (MyThread.WaitReason == ThreadWaitReason.LpcReceive)
- 2022-04-18 07:37:09下载
- 积分:1