惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google Online Security Blog
Google Online Security Blog
博客园_首页
酷 壳 – CoolShell
酷 壳 – CoolShell
Jina AI
Jina AI
博客园 - Franky
大猫的无限游戏
大猫的无限游戏
Hugging Face - Blog
Hugging Face - Blog
博客园 - 司徒正美
V
V2EX
雷峰网
雷峰网
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
F
Full Disclosure
Y
Y Combinator Blog
V
V2EX - 技术
Attack and Defense Labs
Attack and Defense Labs
S
Security @ Cisco Blogs
Schneier on Security
Schneier on Security
Microsoft Azure Blog
Microsoft Azure Blog
SecWiki News
SecWiki News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
The GitHub Blog
The GitHub Blog
量子位
PCI Perspectives
PCI Perspectives
S
Secure Thoughts
D
Darknet – Hacking Tools, Hacker News & Cyber Security
AWS News Blog
AWS News Blog
Blog — PlanetScale
Blog — PlanetScale
爱范儿
爱范儿
K
Kaspersky official blog
B
Blog
A
Arctic Wolf
Hacker News: Ask HN
Hacker News: Ask HN
L
LangChain Blog
T
Tor Project blog
P
Privacy & Cybersecurity Law Blog
Recent Announcements
Recent Announcements
宝玉的分享
宝玉的分享
The Register - Security
The Register - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
Lohrmann on Cybersecurity
D
Docker
A
About on SuperTechFans
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Google DeepMind News
Google DeepMind News
The Last Watchdog
The Last Watchdog
S
Security Affairs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy International News Feed
Simon Willison's Weblog
Simon Willison's Weblog

博客园 - 小罗

学习CRYPTO C#中使用网络函数 (第一部分 用户函数)[翻译] C#图片处理类 在WINCE或Mobile下面获取当前目录 (翻译)从底层了解ASP.NET体系结构 采用HttpModules来重写URLs 使用会话状态(一) 小技巧:ASP.NET中编程杀死进程 - 小罗 - 博客园 ASP.NET—From验证:全部代码及讲解 ASP.NET如何存取 SQLServer数据库图片 ASP.NET基本编程习惯 用asp.net还原与恢复sqlserver数据库 ASP.NET 2.0移动开发之定义设备筛选器 Session丢失原因与解决方案小结 小心!目录删除及重命名操作,一定丢失Session~~ 40 种网页技巧 过滤ASP.NET输出HTML中的无用空格 在ASP.NET中创建安全的web站点(配置) ASP.NET Forums 页面模型分析
C# 文件操作(上传 下载 删除 文件列表...)
小罗 · 2008-01-19 · via 博客园 - 小罗

using System.IO;
  
  1.文件上传
  ----------
  如下要点:
  HTML部分:
  <form id="form1" runat="server" method="post" enctype="multipart/form-data">
  <input id="FileUpLoad" type="file" runat="server"/><br />
  后台CS部分 按钮事件
  //string strFileFullName = System.IO.Path.GetFileName(this.FileUpLoad.PostedFile.FileName);
  //this.FileUpLoad.PostedFile.SaveAs(Server.MapPath("./xmlzip/") + strFileFullName);
  
  2.文件下载
  ----------
  ListBox的SelectedIndexChanged事件 设定相关下载连接
   protected void lst_DownLoadFileList_SelectedIndexChanged(object sender, EventArgs e)
   {
   try
   {
   string strJS = "window.open('xmlzip/";
   strJS += this.lst_DownLoadFileList.SelectedItem.Text.Trim();
   strJS += "'); return false; ";
   this.imgbtn_DownLoadFile.Attributes.Add("onclick", strJS);
   }
   catch (Exception ex)
   {
   ex.ToString();
   }
   }
  或者也可以通过 改变Label的Text值 来实现点击后实现文件下载的超级连接
  this.Label1.Text = "<a href=\"xmlzip/a.rar\">a.rar</a>"
  
  3.文件删除
  ---------
  string strFilePath = 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");
   }
  }
  
  
  4.得到文件夹下的文件列表
  -----------
  #region 得到当前可用的文件列表
   /// <summary>
   /// 得到当前可用的文件列表
   /// </summary>
   /// <param name="IsAlert">是否需要弹出提示信息</param>
   private void fn_getCurrFileList(bool IsAlert)
   {
   try
   {
   //查找xmlzip文件夹下 属于其本身UnitCoding的相关zip文件
   string strXmlZipDirectory = Server.MapPath("../xmlzip/");
   if (Directory.Exists(strXmlZipDirectory))
   {
   //DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory);
   DirectoryInfo di = new DirectoryInfo(strXmlZipDirectory);
  
   FileInfo[] FI = di.GetFiles("*.zip");//只查.zip文件
   if (FI.Length > 0)
   {
   lst_DownLoadFileList.Items.Clear();
   foreach (FileInfo tmpFI in FI)
   {
   ListItem tmpItem = new ListItem();
   tmpItem.Text = tmpFI.Name;
   lst_DownLoadFileList.Items.Add(tmpItem);
   }
   lst_DownLoadFileList.SelectedIndex = 0;
   }
   else
   {
   if (IsAlert)
   {
   Response.write("查无可以下载的文件!");
   }
   }
   }
   }
   catch (Exception ex)
   {
   ex.ToString();
   }
   }
   #endregion
  更多更详细的以后再做补充

posted @ 2008-01-19 15:36  小罗  阅读(547)  评论()    收藏  举报