.NET开发

本类阅读TOP10

·NHibernate快速指南(翻译)
·vs.net 2005中文版下载地址收藏
·【小技巧】一个判断session是否过期的小技巧
·VB/ASP 调用 SQL Server 的存储过程
·?dos下编译.net程序找不到csc.exe文件
·通过Web Services上传和下载文件
·学习笔记(补)《.NET框架程序设计(修订版)》--目录
·VB.NET实现DirectDraw9 (2) 动画
·VB.NET实现DirectDraw9 (1) 托管的DDraw
·建站框架规范书之——文件命名

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
C#:获得文件版本信息及只读文件的删除

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

Author:David Euler
Date: 2004/11/16
Email:
[email protected]

有任何问题,请与我联系:)

获取文件的版本信息:
 FileVersionInfo myFileVersionInfo1 = FileVersionInfo.GetVersionInfo("D:\\TEST.DLL");
 textBox1.Text="版本号: " + myFileVersionInfo1.FileVersion;


更改文件属性,删除只读文件:
下例欲将E:\test.txt文件拷贝至D:\tmp\test.txt,但D:\tmp\test.txt已经存在。
//File.Copy(sourceFile,destinationFile,true); 用来拷贝文件
 //当destinationFile已经存在时,无法将文件file1拷贝到目标文件,
 //因此先删除destination文件,File.Delete()方法不能删除只读文件,
 //因此,如果文件属性为只读(Attributes属性中会包含有"ReadOnly"),
 //先把文件属性重置为Normal,然后再删除:
string file1="E:\\test.txt";
string destinationFile="d:\\tmp\\test.txt";
 if(File.Exists(destinationFile))
 {
  FileInfo fi=new FileInfo(destinationFile);
  if(fi.Attributes.ToString().IndexOf("ReadOnly")!=-1)
   fi.Attributes=FileAttributes.Normal;
  File.Delete(destinationFile);
 }
 File.Copy(file1,destinationFile,true);




相关文章

相关软件