// Upload the Code:
Protected void sh_click (Object sender, eventargs E)
{
String filename = This. fileupload1.filename. Trim ();
String Path = "wenjian/" + filename; // put the uploaded file in the folder named wenjian.
String A = server. mappath ("./"); // obtain the Directory
If (! Directory. exists (a + "wenjian") // create a folder if the folder does not exist
{
Directory. createdirectory (a + "wenjian ");
}
Fileupload1.postedfile. saveas (a + path); // put the uploaded file in the specified path
Page. clientscript. registerstartupscript (GetType (), "", "<SCRIPT> alert ('upload successful! ') </SCRIPT> ");
}
// Download the Code:
Protected void down_click (Object sender, eventargs E)
{
String fileurl = server. mappath ("wenjian/" + "Amy gao_201107 1.docx ");
Fileurl = fileurl. Replace (@ "\ wenjian", @ "\ wenjian"); // cancel invalid characters
Fileinfo = new fileinfo (fileurl );
Response. Clear ();
Response. clearcontent ();
Response. clearheaders ();
Response. addheader ("content-disposition", "attachment; filename =" + server. urlpathencode (fileurl ));
Response. addheader ("Content-Length", fileinfo. length. tostring ());
Response. addheader ("content-transfer-encoding", "binary ");
Response. contenttype = "application/octet-stream ";
Response. contentencoding = system. Text. encoding. getencoding ("gb2312 ");
Response. writefile (fileinfo. fullname );
Response. Flush ();
Response. End ();
}