protected void btnSave_Click(object sender, EventArgs e)
{
// 確定文件夾
string directory = WhichDirectory();
StringBuilder str = new StringBuilder();
if(FileUpload1.HasFile)
{
// 對(duì)上傳文件的類型進(jìn)行過濾,該處只能傳壓縮文件(rar或者zip),這種文件在火狐
瀏覽器中,叫application/octet-stream
if ((this.FileUpload1.PostedFile.ContentType == "application/x-zip-compressed")
|| (this.FileUpload1.PostedFile.ContentType == "application/octet-stream"))
{
try
{
str.AppendFormat("上傳文件名: {0}", FileUpload1.FileName);
// 保存文件
string thefilepath = string.Format(HttpContext.Current.Server.MapPath(("~/
{0}/{1}/") FileUpload1.FileName), "資源", directory);
FileUpload1.SaveAs(thefilepath);
// 顯示文件的信息
str.AppendFormat("<br />正在上傳: {0}", FileUpload1.PostedFile.FileName);
str.AppendFormat("<br />文件類型: {0}",