Exemple #1
0
        /// <summary>
        /// 附件上传
        /// </summary>
        /// <returns></returns>
        public static bool SaveFile(HttpPostedFileBase file, string path, int mailID)
        {
            using (MainDataContext dbContext = new MainDataContext())
            {
                E_Mail_Attachment entity = new E_Mail_Attachment();

                var list = dbContext.E_Mail_Attachment.Select(t => t.ID);
                if (list.LongCount() > 0)
                {
                    entity.ID = list.Max() + 1;
                }
                else
                {
                    entity.ID = 1;
                }

                int lastIndex = file.FileName.LastIndexOf("\\");
                entity.OriginalName = file.FileName.Substring(lastIndex + 1, file.FileName.Length - lastIndex - 1); //原文件名
                entity.CodingName   = System.Guid.NewGuid().ToString() + entity.OriginalName;                       //编码附件名
                entity.Size         = (float)(file.ContentLength * 1.0 / 1024);                                     //文件大小
                entity.MailID       = mailID;

                string _path = path + entity.CodingName;

                file.SaveAs(_path);    //上传至服务器

                dbContext.E_Mail_Attachment.InsertOnSubmit(entity);
                dbContext.SubmitChanges();
                return(true);
            }
        }
Exemple #2
0
        public ActionResult FileDownLoad(int fileId)
        {
            BLL.Email.Email   email = new BLL.Email.Email();
            E_Mail_Attachment cot   = email.DownLoadFile(fileId);

            string path = AppConfig.GetUpload() + cot.CodingName;

            return(new DownloadResult {
                VirtualPath = path, FileDownloadName = cot.OriginalName
            });
        }