using System.IO;
如下要點:
HTML部分:
- <form id="form1" runat="server" method="post" enctype="multipart/form-data">
- <input id="FileUpLoad" type="file" runat="server"/><br />
- string strFileFullName = System.IO.Path.GetFileName(this.FileUpLoad.PostedFile.FileName);
- this.FileUpLoad.PostedFile.SaveAs(Server.MapPath("./xmlzip/") + trFileFullName);
----------
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();
}
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))
{