Submit.aspx
<%@ Page language= "C #" autoeventwireup= "true" aspcompat= "true" codefile= "Submit.aspx.cs" inherits= "Submit"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> Untitled Page </title>
<body bgcolor= "#dae5e9" >
<form id= "Form1" runat= "Server" >
<table width= "780" border= "0" cellspacing= "0" cellpadding= "0" align= "center" >
<tr bgcolor= "#A3CEEE" >
<TD height= ><strong> Select and upload accessories </strong></td>
</tr>
<tr>
<TD height= ">1", click "Browse ..." button, select the attachment you want to submit;</td>
</tr>
<tr>
<TD height= "><asp:fileupload" id= "FileUpload1" runat= "Server"/></td>
</tr>
<tr>
<TD height= ">2", click <asp:button id= "btnupload" runat= "server" text= "upload" onclick= "btnupload_click"/> Button, Upload the attachment;</td>
</tr>
<tr>
<TD height= ">3", if you need to submit more than one attachment, please repeat the steps 1 and 2 above;</td>
</tr>
<tr>
<TD height= ">4", all the attachments after uploading, click <asp:button id= "btnsave" runat= "Server" text= "complete" onclick= "Btnsave_click"/ > button to return. </td>
</tr>
<tr bgcolor= "#A3CEEE" >
<TD height= ><strong> Remove unwanted attachments </strong> (Please select the attachment you want to delete, then click the <strong> Remove </strong> button.) ) </td>
</tr>
<tr>
<TD height= > Accessories list:
<asp:dropdownlist id= "Attachments" runat= "Server" >
<asp:listitem value= "-1" selected= "True" > Attachment list ...</asp:listitem>
</asp:DropDownList>
<asp:button id= "Btndelete" runat= "server" text= "delete" onclick= "Btndelete_click"/>
Total: <asp:label id= "Lbattachfilenumber" runat= "server" text= "0" width= "40px" ></asp:Label> Accessories
Total size: <asp:label id= "lbfilesize" runat= "server" text= "0" width= "40px" ></asp:Label> bytes
</td>
</tr>
</table>
</form>
</body>
**********************************************************************
Submit.aspx.cs
Using System;
Using System.Data;
Using System.Configuration;
Using System.Collections;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
Using System.IO;
public partial class Submit:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
if (! IsPostBack)
{//involved in the database, need to display the attachment list and other related content (omitted here)
}
}
Number of attachments
int _attachfilenumber;
public int Attachfilenumber
{
get {return this._attachfilenumber;}
set {This._attachfilenumber = value;}
}
Total size of attachment
int _filesize;
public int FileSize
{
get {return this._filesize;}
set {this._filesize = value;}
}
directory where attachments are located
String _attachmentlinks = "";
public string Attachmentlinks
{
get {return this._attachmentlinks;}
set {this._attachmentlinks = value;}
}
protected void Btnupload_click (object sender, EventArgs e)
{
Try
{
if (this. FileUpload1.FileName.Length > 0)
{
string filename = "";
filename = this. Fileupload1.filename;
filename = DateTime.Now.ToString ("YYYYMMDDHHMMSS") + filename;
This. FileUpload1.PostedFile.SaveAs (request.servervariables["Appl_physical_path"] + "temp//" + filename);
THIS.ATTACHMENTS.ITEMS.ADD (filename) (new ListItem);
_attachfilenumber = Int. Parse (This.lbAttachFileNumber.Text) + 1;
This.lbAttachFileNumber.Text = _attachfilenumber.tostring ();
_filesize = Int. Parse (This.lbFileSize.Text) + this. FileUpload1.PostedFile.ContentLength;
This.lbFileSize.Text = _filesize. ToString ();
}
Else
{
Response.Write (' <script>alert (') please select an attachment. ') </script> ");
}
}
catch (Exception ex)
{
Response.Write (ex. Message.tostring ());
}
}
protected void Btnsave_click (object sender, EventArgs e)
{//involving the database, implementing the operations saved to the database (omitted here).
}
protected void Btndelete_click (object sender, EventArgs e)
{
Try
{
String ppath = request.servervariables["Appl_physical_path"] + "temp//" + this.attachments.SelectedItem;
This.attachments.Items.Remove (This.attachments.SelectedItem);
if (file.exists (Ppath))
{
FileInfo FileInfo = new FileInfo (Ppath);
_attachfilenumber = Int. Parse (This.lbAttachFileNumber.Text)-1;
int fsize = Convert.ToInt32 (FileInfo. Length);
_filesize = Int. Parse (This.lbFileSize.Text)-fsize;
This.lbAttachFileNumber.Text = _attachfilenumber.tostring ();
This.lbFileSize.Text = _filesize. ToString ();
File.delete (Ppath);
}
}
catch (Exception ex)
{
Response.Write (ex. Message.tostring ());
}
}
}