温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

C#文件列表操作有哪些重点

发布时间:2021-07-16 16:15:41 来源:亿速云 阅读:164 作者:chen 栏目:编程语言

本篇内容主要讲解“C#文件列表操作有哪些重点”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“C#文件列表操作有哪些重点”吧!

C#文件列表要点1:上传文件

HTML部分:

〈 formid=\"form1\"runat=\" server\"method=\"post\"enctype=\  "multipart/form-data\"〉  〈 inputid=\"FileUpLoad\"type=\" file\"runat=\"server\"/〉〈 br/〉  后台CS部分按钮事件  //stringstrFileFullName=  System.IO.Path.GetFileName(this.  FileUpLoad.PostedFile.FileName);  //this.FileUpLoad.PostedFile.SaveAs(Server.MapPath(  \"./Xmlzip/\")+strFileFullName);

C#文件列表要点2.文件下载

ListBox的SelectedIndexChanged事件设  定相关下载连接  protectedvoidlst_DownLoadFileList  _SelectedIndexChanged(objectsender,EventArgse)  {  try  {  stringstrJS=\"window.open(\'Xmlzip/\";  strJS+=this.lst_DownLoadFileList.  SelectedItem.Text.Trim();  strJS+=\"\');returnfalse;\";  this.imgbtn_DownLoadFile.Attributes.  Add(\"onclick\",strJS);  }  catch(Exceptionex)  {  ex.ToString();  }  }  或者也可以通过改变Label的Text值来实现点击  后实现文件下载的超级连接  this.Label1.Text=\"〈 ahref=  \\\"Xmlzip/a.rar\\\"〉a.rar〈 /a〉\"

C#文件列表要点3.文件删除

stringstrFilePath=Server.MapPath(  \"../CountryFlowMgr/Xmlzip/\"+this.lst_  DownLoadFileList.SelectedItem.Text.Trim());  if(File.Exists(strFilePath))  {  File.Delete(strFilePath);  if(File.Exists(strFilePath))  {  Response.Write(\"ok\");  }  else {  Response.Write(\"ok\");  }  }

C#文件列表要点4.得到文件夹下的文件列表

#region得到当前可用的文件列表  ///〈 summary〉  ///得到当前可用的文件列表  ///〈 /summary〉  ///〈 paramname=\"IsAlert\"〉  是否需要弹出提示信息〈 /param〉  privatevoidfn_getCurrFileList(boolIsAlert)  {  try  {  //查找Xmlzip文件夹下属于其本  身UnitCoding的相关zip文件  stringstrXmlZipDirectory=  Server.MapPath(\"../Xmlzip/\");  if(Directory.Exists(strXmlZipDirectory))  {  //DirectoryInfodi=newDirectoryInfo(  Environment.CurrentDirectory);  DirectoryInfodi=newDirectoryInfo(  strXmlZipDirectory);   FileInfo[]FI=di.GetFiles(\"*.zip\" );//只查.zip文件  if(FI.Length〉0)  {  lst_DownLoadFileList.Items.Clear();  foreach(FileInfotmpFIinFI)  {  ListItemtmpItem=newListItem();  tmpItem.Text=tmpFI.Name;  lst_DownLoadFileList.Items.Add(tmpItem);  }  lst_DownLoadFileList.SelectedIndex=0;  }  else {  if(IsAlert)  {  Response.write(\"查无可以下载的文件!\");  }  }  }  }  catch(Exceptionex)  {  ex.ToString();  }  }  #endregion

到此,相信大家对“C#文件列表操作有哪些重点”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI