Upload | download
Using System.IO;
1. File Upload
----------
The following points:
HTML section:
<form id= "Form1" runat= "Server" method= "POST" enctype= "Multipart/form-data" >
<input id= "FileUpload" type= "file" runat= "server"/><br/>
Background CS Partial button Event
String strfilefullname = System.IO.Path.GetFileName (this. FileUpLoad.PostedFile.FileName);
This. FileUpLoad.PostedFile.SaveAs (Server.MapPath ("./xmlzip/") + Strfilefullname);
2. File download
----------
ListBox SelectedIndexChanged Event settings Related download connection
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 ();
}
}
Or you can change the label of the text value to achieve a click to implement the file download super connection
This. Label1.Text = "<a href=\" xmlzip/a.rar\ ">a.rar</a>"
3. File deletion
---------
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. Get the file list under the folder
-----------
#region get a list of currently available files
<summary>
Get a list of currently available files
</summary>
<param name= "Isalert" > whether pop-up prompts are required </param>
private void Fn_getcurrfilelist (bool isalert)
{
Try
{
Find a related zip file in the Xmlzip folder that is subordinate to its own unitcoding
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")//Only check the. zip file
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 ("Check no downloadable files!");
}
}
}
}
catch (Exception ex)
{
Ex. ToString ();
}
}
#endregion