Example #1
0
 /// <summary>
 ///  上传文件到服务器
 /// </summary>
 /// <param name="id">id</param>
 /// <param name="type">type</param>
 /// <param name="file">file</param>
 /// <param name="folderName">文件夹名称</param>
 /// Author  : Napoleon
 /// Created : 2015-05-08 16:14:24
 public ActionResult UploadFile(string id, string type, HttpPostedFileBase file, string folderName)
 {
     try
     {
         string localPath = Path.Combine(HttpRuntime.AppDomainAppPath, "UploadFiles\\" + folderName);
         if (Request.Files.Count == 0)//没有上传的文件
         {
             return(Json(new { jsonrpc = 2.0, message = "没有文件可以上传!", id }));
         }
         string filePathName = Guid.NewGuid().ToString("N") + Path.GetExtension(file.FileName);
         if (!Directory.Exists(localPath))
         {
             Directory.CreateDirectory(localPath);
         }
         string serverPath = Path.Combine(localPath, filePathName);
         file.SaveAs(serverPath);//保存到服务器端
         NewsUploadFile files = new NewsUploadFile();
         files.Id         = CustomId.GetCustomId();
         files.FileTilte  = file.FileName;
         files.FileUrl    = "/UploadFiles/" + folderName + "/" + filePathName;
         files.UploadTime = DateTime.Now;
         int i = _newsUploadFile.InsertNewsUploadFile(files);//文件信息保存到数据库
         if (i > 0)
         {
             return(Json(new { jsonrpc = 2.0, message = "success", id, hiddenId = files.Id }));
         }
         return(Json(new { jsonrpc = 2.0, message = "文件保存失败!", id }));
     }
     catch (Exception)
     {
         return(Json(new { jsonrpc = 2.0, message = "文件保存出错!", id }));
     }
 }
Example #2
0
        /// <summary>
        ///  更新数据
        /// </summary>
        /// Author  :Napoleon
        /// Created :2015-06-06 02:02:28
        public int UpdateNewsUploadFile(NewsUploadFile model)
        {
            StringBuilder sql = new StringBuilder();

            sql.AppendFormat("update News_UploadFile set Id=@Id,FileTilte=@FileTilte,FileUrl=@FileUrl,UploadTime=@UploadTime,OrderBy=@OrderBy where Id=@Id");
            int i = DbHelper.ExecuteSql(sql.ToString(), model);

            return(i);
        }
Example #3
0
        /// <summary>
        ///  新增数据
        /// </summary>
        /// Author  :Napoleon
        /// Created :2015-06-06 02:02:28
        public int InsertNewsUploadFile(NewsUploadFile model)
        {
            StringBuilder sql = new StringBuilder();

            sql.AppendFormat("insert into News_UploadFile(Id,FileTilte,FileUrl,UploadTime,OrderBy) values(@Id,@FileTilte,@FileUrl,@UploadTime,@OrderBy)");
            int i = DbHelper.ExecuteSql(sql.ToString(), model);

            return(i);
        }
 /// <summary>
 ///  更新数据
 /// </summary>
 /// Author  :Napoleon
 /// Created :2015-06-06 02:02:28
 public int UpdateNewsUploadFile(NewsUploadFile model)
 {
     return(_newsuploadfileDao.UpdateNewsUploadFile(model));
 }
 /// <summary>
 ///  新增数据
 /// </summary>
 /// Author  :Napoleon
 /// Created :2015-06-06 02:02:28
 public int InsertNewsUploadFile(NewsUploadFile model)
 {
     return(_newsuploadfileDao.InsertNewsUploadFile(model));
 }