コード例 #1
0
      private tbl_files editfile(fileViewModel vf)
      {
          tbl_files f = null;

          try
          {
              f              = new tbl_files();
              f.fileID       = 1;
              f.fileDispName = Path.GetFileName(vf.file.FileName);
              //if (f.fileDispName.Length > 50) { f = null; return f; }
              f.fileDescription = vf.description;
              f.fileCourse      = vf.courseID;
              f.fileType        = Path.GetExtension(vf.file.FileName);

              string filepath = System.Web.HttpContext.Current.Server.MapPath($"../assets/files/{f.fileDispName}");
              filepath = filepath.Replace("\\Files", "");
              if (!System.IO.File.Exists(filepath))
              {
                  vf.file.SaveAs(filepath);
                  f.filePath = filepath;
                  return(f);
              }
              else
              {
                  f = null;
                  return(f);
              }
          }
          catch (Exception ex)
          {
              return(f);
          }
      }
コード例 #2
0
      public ActionResult Create(fileViewModel vf)
      {
          try
          {
              tbl_files files = savefile(vf);
              if (files != null)
              {
                  db.tbl_files.Add(files);

                  db.SaveChanges();
                  return(Json("success", JsonRequestBehavior.AllowGet));
              }
              else
              {
                  return(Json("Failed to upload file Please rename the file to smaller name and reupload it", JsonRequestBehavior.AllowGet));
              }
          }
          catch (Exception ex)
          {
              return(Json(ex.Message, JsonRequestBehavior.AllowGet));
          }
      }