1 /// <summary>
2 /// 上传附件
3 /// </summary>
4 /// <returns></returns>
5 [WebMethod]
6 public string File_UploadFile()
7 {
8 string result = "";
9
10 try
11 {
12 string UserId = System.Web.HttpContext.Current.Request["UserId"];
13 string UserName = System.Web.HttpContext.Current.Request["UserName"];
14 string FileName = System.Web.HttpContext.Current.Request["FileName"];
15 string FolderId = System.Web.HttpContext.Current.Request["FolderId"];
16 HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
17 if (files.Count > 0)
18 {
19 List<FileUploadModel> UploadFileList = new List<FileUploadModel>();
20
21 for (int i = 0; i < files.Count; i++)
22 {
23 //Step1: 接收文件并保存
24 HttpPostedFile file = files[i];
25 file.SaveAs(Server.MapPath("Upload/"+ FileName));
26
27 //Step2: 读取文件信息
28 FileUploadModel fileUploadModel = new FileUploadModel();
29 fileUploadModel.FileName = FileName;
30 fileUploadModel.FilePath = Server.MapPath("Upload/" + FileName);
31
32 UploadFileList.Add(fileUploadModel);
33 }
34
35 //Step3: 开始上传
36 SCFileBLL fileBLL = new SCFileBLL();
37 if (fileBLL.UploadFileById(UploadFileList, FolderId, UserId, UserName) > 0)
38 {
39 result = "Success";
40 }
41
42 //Step4: 删除临时文件
43 try
44 {
45 for (int i = 0; i < files.Count; i++)
46 {
47 System.IO.File.Delete(Server.MapPath("Upload/" + FileName));
48 }
49 }
50 catch (Exception ex)
51 {
52
53 }
54 }
55 }
56 catch (Exception ex)
57 {
58 result = ex.Message;
59 }
60
61 return result;
62 }