Пример #1
0
        public string Files(HttpPostedFileBase AttachmentFile)
        {
            dynamic jr = new ExpandoObject();
            bool uploadOK = false;
            string error = string.Empty;
            string fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff_") + AttachmentFile.FileName;
            string filePhysicalPath = Server.MapPath("~/Attribute/" + fileName);
            string filePath = "";
            try
            {
                AttachmentFile.SaveAs(filePhysicalPath);
                string extensionName = System.IO.Path.GetExtension(AttachmentFile.FileName).TrimStart('.').ToLower();
                filePath = "/Attribute/" + fileName;
                uploadOK = true;
                jr.fileName = AttachmentFile.FileName;
                jr.url = filePath;
                jr.type = AttachmentFile.ContentType;
                jr.length = Utils.ConvertBytes(AttachmentFile.ContentLength);
                jr.fontCode = Utils.GetFileLogoStr(extensionName);

                AttachmentItem ai = new AttachmentItem();
                ai.FileFontCode = jr.fontCode;
                ai.FileLength = jr.length;
                ai.FilePath = filePath;
                ai.FileType = jr.type;
                ai.FileName = AttachmentFile.FileName;
                string guid = AttachmentManager.Instance.Add(ai);
                if (string.IsNullOrEmpty(guid))
                {
                    Qing.QLog.SendLog_Exception("文件上传入库失败", "AttributeManager");
                    uploadOK = false;
                }
                else
                {
                    jr.id = guid;
                }

            }
            catch (Exception ex)
            {
                error = ex.Message;
                Qing.QLog.SendLog(ex.ToString());
                jr.message = error;
            }

            jr.success = uploadOK ? 1 : 0;
            return JsonConvert.SerializeObject(jr);
        }
Пример #2
0
 public string Add(AttachmentItem ai)
 {
     ai.GUID = Guid.NewGuid().ToString().Replace("-", "");
     ai.UpLoadTime = DateTime.Now;
     string sql = ai.GetInsertSQL("AttachmentList");
     var conn = MySQLConnectionPool.GetConnection();
     var result = conn.Execute(sql);
     conn.GiveBack();
     if (result > 0)
     {
         return ai.GUID;
     }
     else
     {
         return null;
     }
 }