protected void Btnupload_click (object sender, EventArgs e)
{String type;
if (ddlist. Selecteditem.value = "")
{
Scriptmanager.registerstartupscript (this, this.) GetType (), "", "alert (' You have not chosen a column '); window.location.href= ' user.aspx ';", true);
Return
}
Else
{
Type = Ddlist. Selecteditem.value;
viewstate["type" = type;
Ddlist. Enabled = false;
}
Boolean FileOK = true;
if (fufile.hasfile)
{
if (FileOK)
{
Try
{
String Date = System.DateTime.Now.ToString ("Yymmddhhmmss");
String subfie = FUfile.FileName.Substring (FUfile.FileName.LastIndexOf ("."), 4);
String Slocalpath = ".. /common/wwjeditor/uploadfiles/";
String folder = Server.MapPath (Slocalpath) + type;
if (! Directory.Exists (folder))
Directory.CreateDirectory (folder);
String path = folder + "//" + Date + subfie;
string fileName = Fufile.filename;
int size = FUfile.PostedFile.ContentLength;
//String userName = type;
Multimedia Mul = new multimedia ();
Mul. Name = FileName;
Mul. size = size;
Mul. Path = "common/wwjeditor/uploadfiles/" + type + "/" + Date + subfie;
Mul. Series = 1;
Upload to Folder
Slocalpath = ".. /common/wwjeditor/uploadfiles/"+ type;
Path = Server.MapPath (Slocalpath) + "//" + Mul. Path.substring (Mul. Path.lastindexof ("/") + 1);
if (! File.exists (PATH))
{
Fufile.saveas (path);
}
if (viewstate["list"]!= null)
{
list<multimedia> list = (list<multimedia>) viewstate["list";
Mul. Series = list. Count + 1;
List. ADD (MUL);
Gvaccessory.datasource = list;
Gvaccessory.databind ();
}
Else
{
list<multimedia> list = new list<multimedia> ();
List. ADD (MUL);
viewstate["List" = list;
Gvaccessory.datasource = list;
Gvaccessory.databind ();
}
}
catch (System.Exception ex)
{
Response.Write ("<script>alert" + ex. Message + "');</script>");
Return
}
}
}
Else
{
Response.Write (' <script>alert ' uploaded file does not meet the requirements. ');</script> ");
Return
}
}
Source file Address
http://blog.csdn.net/loveheronly/article/details/6669660%E5%B0%B1%E6%98%AF%E6%97%A0%E5%88%B7%E6%96%B0%E7%9A%84