c# doc文件上传

 1         protected void Upload_Click(object sender, EventArgs e)
 2         {
 3             string ls_docid = HttpContext.Current.Request["key"];
 4             if (string.IsNullOrEmpty(ls_docid)) 
 5             {
 6                 return;
 7             }
 8             string ls_extension = System.IO.Path.GetExtension(fpFileUp.FileName).ToLower();
 9             string filePath = fpFileUp.PostedFile.FileName;
10             string fileName = fpFileUp.FileName;
11             if ((ls_extension != ".doc") && (ls_extension != "docx"))
12             {
13                 Page.ClientScript.RegisterStartupScript(typeof(string), "", "<script>showTopMsg('抱歉,只能是 .doc或docx格式的文件!',2000,'error');</script>");
14                 return;
15             }
16 
17             filePath = string.IsNullOrEmpty(fpFileUp.PostedFile.FileName) ? AccessFile : this.fpFileUp.PostedFile.FileName;
18             AccessFile = filePath;
19             //服务器的存储路径
20             string ls_SaveURL = "/DocFile/" + gydate.of_GetTodayStr() + "/";
21             string savePath = HtmlComm.gf_GetSavePath();
22 
23             if (File.Exists(fileName)) { File.Delete(fileName); }
24             //生成一个不重复的文件名
25             fileName = Path.GetFileNameWithoutExtension(fileName) + "_" + GYstring.of_GetNewGuid() + Path.GetExtension(fileName);
26             fpFileUp.SaveAs(savePath + fileName);
27             n_create_sql lnv_anw = new n_create_sql("docAnswer");
28             lnv_anw.of_AddCol("upurl", savePath + fileName);
29             lnv_anw.of_execute("docid=@docid", "@docid=" + ls_docid);
30 
31             Page.ClientScript.RegisterStartupScript(typeof(string), "", "<script>showTopMsg('附件已上传!',2000,'success');</script>");
32 
33         }

 

posted @ 2018-01-07 15:26  伏地魔程序员  阅读(294)  评论(0编辑  收藏  举报