コード例 #1
0
 protected void publish_attachment_upload_OnFileUploaded(object sender, FileUploadedEventArgs e)
 {
     var aid = HomoryContext.Value.GetId();
     var id = CurrentResource.Id;
     var file = e.File;
     var name = string.Format("../Common/资源/{2}/附件/{1}_{0}", file.FileName, aid, CurrentUser.Id.ToString().ToUpper());
     var sourceX = Server.MapPath(name);
     var pathX = string.Format("../Common/资源/{2}/附件/{1}_{0}", file.GetNameWithoutExtension(), aid, CurrentUser.Id.ToString().ToUpper());
     file.SaveAs(Server.MapPath(name), true);
     ResourceFileType type;
     switch (file.GetExtension().Replace(".", ""))
     {
         case "jpg":
         case "jpeg":
         case "png":
         case "gif":
         case "bmp":
             type = ResourceFileType.Image;
             break;
         case "rar":
         case "zip":
         case "7z":
             type = ResourceFileType.Zip;
             break;
         case "doc":
         case "docx":
         case "txt":
         case "rtf":
             type = ResourceFileType.Word;
             pathX += ".pdf";
             pathX = Server.MapPath(pathX);
             var docW = new Aspose.Words.Document(sourceX);
             docW.Save(pathX, Aspose.Words.SaveFormat.Pdf);
             break;
         case "ppt":
         case "pptx":
             type = ResourceFileType.Powerpoint;
             pathX += ".pdf";
             pathX = Server.MapPath(pathX);
             var docP = new Aspose.Slides.Presentation(sourceX);
             docP.Save(pathX, Aspose.Slides.Export.SaveFormat.Pdf);
             break;
         case "xls":
         case "xlsx":
             type = ResourceFileType.Excel;
             pathX += ".pdf";
             pathX = Server.MapPath(pathX);
             var docE = new Aspose.Cells.Workbook(sourceX);
             docE.Save(pathX, Aspose.Cells.SaveFormat.Pdf);
             break;
         case "pdf":
             type = ResourceFileType.Pdf;
             break;
         case "mp3":
         case "wma":
             type = ResourceFileType.Audio;
             break;
         default:
             type = ResourceFileType.Media;
             break;
     }
     var ra = new ResourceAttachment
     {
         Id = aid,
         ResourceId = id,
         FileType = type,
         Title = file.GetName(),
         Remark = remarkTextbox.Text,
         Source = name,
         State = State.启用
     };
     HomoryContext.Value.ResourceAttachment.Add(ra);
     HomoryContext.Value.SaveChanges();
 }
コード例 #2
0
 protected void publish_attachment_upload_OnFileUploaded(object sender, FileUploadedEventArgs e)
 {
     var id = CurrentResource.Id;
     var file = e.File;
     ResourceFileType type;
     switch (file.GetExtension().Replace(".", ""))
     {
         case "jpg":
         case "jpeg":
         case "png":
         case "gif":
         case "bmp":
             type = ResourceFileType.Image;
             break;
         case "rar":
         case "zip":
         case "7z":
             type = ResourceFileType.Zip;
             break;
         case "doc":
         case "docx":
         case "txt":
         case "rtf":
             type = ResourceFileType.Word;
             break;
         case "ppt":
         case "pptx":
             type = ResourceFileType.Powerpoint;
             break;
         case "xls":
         case "xlsx":
             type = ResourceFileType.Excel;
             break;
         case "pdf":
             type = ResourceFileType.Pdf;
             break;
         default:
             type = ResourceFileType.Media;
             break;
     }
     var name = string.Format("../Common/资源/{2}/附件/{1}_{0}", file.FileName, HomoryContext.Value.GetId(), CurrentUser.Id.ToString().ToUpper());
     file.SaveAs(Server.MapPath(name), true);
     var ra = new ResourceAttachment
     {
         Id = HomoryContext.Value.GetId(),
         ResourceId = id,
         FileType = type,
         Title = file.GetName(),
         Source = name,
         State = State.启用
     };
     HomoryContext.Value.ResourceAttachment.Add(ra);
     HomoryContext.Value.SaveChanges();
 }