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

首頁 > 編程 > .NET > 正文

利用Asp.net IO.File類完成文件新建復制刪除操作(代碼調試通過)

2024-07-10 13:05:48
字體:
來源:轉載
供稿:網友

private void button1_click(object sender, system.eventargs e)
  {//新建文件
   string path=server.mappath("index4.aspx");  
   //response.write(datetime.now.tostring("yyyymmdd"));
  
   //獲得文件名
   int filelen=path.lastindexof(".");
   int pathlen=path.length;
   string tempname=path.substring(filelen,pathlen-filelen);
   //獲取文件路徑
   int len=path.lastindexof(@"/");
   string temppath=path.substring(0,len)+"http://"+datetime.now.tostring("yyyymmddhhssmm")+tempname;
   try
   {
    file.create(temppath);
    response.write("<script>alert('新建文件成功');</script>");
   }
   catch(exception ex)
   {
    response.write(ex.tostring());
   }
  }

  private void button2_click(object sender, system.eventargs e)
  {//復制文件
   string path=server.mappath("index4.aspx");  
   //response.write(datetime.now.tostring("yyyymmdd"));
  
   //獲得文件名
   int filelen=path.lastindexof(".");
   int pathlen=path.length;
   string tempname=path.substring(filelen,pathlen-filelen);
   //獲取文件路徑
   int len=path.lastindexof(@"/");
   string temppath=path.substring(0,len)+"http://"+datetime.now.tostring("yyyymmddhhssmm")+tempname;
   try
   {
    file.copy(path,temppath);   
    response.write("<script>alert('復制文件成功');</script>");
   }
   catch(exception ex)
   {
    response.write(ex.tostring());
   }
  }

  private void button3_click(object sender, system.eventargs e)
  {//刪除文件
   string path=server.mappath("index4.aspx");  
   //response.write(datetime.now.tostring("yyyymmdd"));
  
   //獲得文件名
   int filelen=path.lastindexof(".");
   int pathlen=path.length;
   string tempname=path.substring(filelen,pathlen-filelen);
   //獲取文件路徑
   int len=path.lastindexof(@"/");
   //string temppath=path.substring(0,len)+"http://"+datetime.now.tostring("yyyymmddhhssmm")+tempname;
   string temppath=path.substring(0,len)+"http://"+"20063702021337.aspx";
  
   try
   {
    file.delete(temppath);   
    response.write("<script>alert('刪除文件成功');</script>");
   }
   catch(exception ex)
   {
    response.write(ex.tostring());
   }
  }


 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 虹口区| 嘉兴市| 区。| 象山县| 吉水县| 宣汉县| 勃利县| 抚远县| 大埔区| 出国| 横山县| 佛坪县| 吉林市| 襄樊市| 革吉县| 昌乐县| 革吉县| 外汇| 饶阳县| 洮南市| 左云县| 景东| 新竹县| 顺义区| 梅州市| 临高县| 永定县| 顺义区| 双流县| 明水县| 峨眉山市| 沾化县| 温泉县| 吉水县| 汉寿县| 三亚市| 阜平县| 麦盖提县| 永兴县| 吉水县| 屯昌县|