国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

Visual C#程序設計技巧小結

2024-07-21 02:26:41
字體:
來源:轉載
供稿:網友
菜鳥學堂:
獲取文件的版本信息:

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);

  c#中字符串的格式化及轉換成數值的方法

  字符串轉換成數字,比如"1234"轉換成數字1234:

string str="1234";
int i=convert.toint32(str);

  格式化字符串,向長度小于30的字符串末尾添加特定字符,補足n個字符,使用string類的padright(int,char)方法:

string str="1234";
str=str.padright(30,' ') //向長度小于30的字符串末尾添加空格,補足30個字符

  按行讀寫文件

  判斷文件是否存在:file.exists(string filepath)

  判斷目錄是否存在:directory.exists("d://lastestversion")

  按行讀取文件:

int filecount=0;
// open the file just specified such that no one else can use it.
streamreader sr = new streamreader(textbox1.text.trim());
while(sr.peek() > -1)//streamreader.peek()返回下一個可用字符,但不使用它
{
 listbox1.items.add(sr.readline());
 filecount++;
}
sr.close();

  按行寫入文件:

streamwriter sw = new streamwriter("d://result.txt");
for(int i=0;i<10;i++)
{
 sw.writeline("這是第"+i.tostring()+"行數據");
}

  文件目錄對話框的使用

  文件對話框即過濾條件的使用:

string resultfile="";
openfiledialog openfiledialog1 = new openfiledialog();
openfiledialog1.initialdirectory = "d://patch" ;
openfiledialog1.filter = "all files (*.*)|*.*|txt files (*.txt)|*.txt" ;
openfiledialog1.filterindex = 2 ;
openfiledialog1.restoredirectory = true ;
if(openfiledialog1.showdialog() == dialogresult.ok)
resultfile=openfiledialog1.filename;

  目錄對話框的使用:

string resultfolder="";
folderbrowserdialog openfolderdialog1=new folderbrowserdialog();
openfolderdialog1.rootfolder=environment.specialfolder.mycomputer;
if(openfolderdialog1.showdialog()==dialogresult.ok)
resultfolder=openfolderdialog1.selectedpath;
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 怀仁县| 申扎县| 铜山县| 通道| 突泉县| 光山县| 石台县| 姚安县| 阿拉善左旗| 望谟县| 祁连县| 重庆市| 贡山| 卫辉市| 新竹市| 民勤县| 大宁县| 肥城市| 昌平区| 固安县| 克山县| 奇台县| 屏东县| 漳平市| 修武县| 扎鲁特旗| 卢龙县| 葵青区| 和静县| 桂阳县| 栾川县| 西畴县| 长治县| 平果县| 常熟市| 岱山县| 哈尔滨市| 揭阳市| 和平县| 株洲市| 高密市|