国产探花免费观看_亚洲丰满少妇自慰呻吟_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());
   }
  }


 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 信宜市| 崇左市| 樟树市| 云林县| 屏东市| 金塔县| 华容县| 乌兰县| 商城县| 平陆县| 城步| 吕梁市| 景德镇市| 呼和浩特市| 张北县| 云龙县| 丰城市| 浑源县| 汕头市| 新津县| 阳春市| 多伦县| 无极县| 布尔津县| 康平县| 芮城县| 宁海县| 高尔夫| 化州市| 获嘉县| 文水县| 梅河口市| 临西县| 青川县| 荣昌县| 托克逊县| 绥中县| 陇川县| 九台市| 汪清县| 荔波县|