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);
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
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〉\"
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
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\");
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
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
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
【编辑推荐】