Exemplo n.º 1
0
        /// <summary>
        /// 下载附件
        /// </summary>
        /// <param name="fileId">附件编码</param>
        /// <returns></returns>
        public ActionResult FileDownLoad(int fileId)
        {
            Flow flow             = new Flow();
            F_INST_ATTACHMENT cot = flow.DownLoadAttacment(fileId);

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

            return(new DownloadResult {
                VirtualPath = path, FileDownloadName = cot.OriginalName
            });
        }
Exemplo n.º 2
0
        public static bool Save(int flowId, int flowNo, HttpPostedFileBase file, string path)
        {
            using (MainDataContext dbContext = new MainDataContext())
            {
                try
                {
                    F_INST_ATTACHMENT entity = new F_INST_ATTACHMENT();

                    var list = dbContext.F_INST_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.FlowID       = flowId;
                    entity.FlowNo       = flowNo;

                    string _path = path + entity.CodingName;

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


                    dbContext.F_INST_ATTACHMENT.InsertOnSubmit(entity);
                    dbContext.SubmitChanges();

                    return(true);
                }
                catch (Exception ex)
                {
                    Log4Net.LogError("Workflow Upload", ex.ToString());

                    return(false);
                }
            }
        }