首页 > Windows开发 > 详细

c# doc文件上传

时间:2018-01-07 16:56:52      阅读:297      评论:0      收藏:0      [点我收藏+]
 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         }

 

c# doc文件上传

原文:https://www.cnblogs.com/cxyzhangjie/p/8228149.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!