码迷,mamicode.com
首页 > Windows程序 > 详细

c# doc文件上传

时间:2018-01-07 17:29:20      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:success   out   ror   docx   filename   delete   exists   url   get   

 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文件上传

标签:success   out   ror   docx   filename   delete   exists   url   get   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!