c# doc文件上传

2021-05-15 12:51

阅读:713

标签: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), "", "");
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), "", "");
32 
33         }

 

c# doc文件上传

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

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


评论


亲,登录后才可以留言!