File Upload

File Upload

samevedzisamevedzi Posts: 30Questions: 5Answers: 0

Hi,

I am trying to do file upload but I am getting the following error: File upload requires that 'Process' be called with an HttpRequest or UnvalidatedRequestValues object. I am using .Net Framework 4.5.2 and Editor-NETFramework-1.9.2. The Server Side script is shown below:

        public ActionResult CRUD()
        {
            try
            {
                var formData = HttpContext.ApplicationInstance.Context.Request;
                var settings = iSource_Editor.Properties.Settings.Default;

                using (var db = new Database(settings.DbType, settings.DbConnection))
                {
                    int User_ID = (int)Session["ID"];
                    var response = new Editor(db, "Contract_Doc_Name", "ID")
                        .Model<Contract_Doc_Name>()
                        .Field(
                            new Field("File_ID")
                                .Upload(
                                    new Upload(formData.PhysicalApplicationPath + @"Uploads\__ID____EXTN__")
                                        .Db("Files", "ID", new Dictionary<string, object>
                                        {
                                            {"web_path", Upload.DbType.WebPath},
                                            {"system_path", Upload.DbType.SystemPath},
                                            {"filename", Upload.DbType.FileName},
                                            {"filesize", Upload.DbType.FileSize}
                                        })
                                )
                                .SetFormatter(Format.NullEmpty())
                        )
                        .Field(new Field("CreatedBy").Set(Field.SetType.Create).SetValue(User_ID))
                        .Field(new Field("CreatedDate").Set(Field.SetType.Create).SetValue(DateTime.Now))
                        .Field(new Field("ModifiedBy").Set(Field.SetType.Both).SetValue(User_ID))
                        .Field(new Field("ModifiedDate").Set(Field.SetType.Both).SetValue(DateTime.Now));

                    response.Process(formData.Unvalidated);
                    DtResponse data = response.Data();
                    return Json(data, JsonRequestBehavior.AllowGet);
                }
            }
            catch (Exception Ex)
            {
                return Json(new { error = Ex.Message.ToString() }, JsonRequestBehavior.AllowGet);
            }
        }

I tried following the forum at : https://datatables.net/forums/discussion/60907 but the file provided is no longer available.

Kindly assist.

Thanks,
---Stephen

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Hi Stephen,

    If you were to use just response.Process(formData); does it allow the upload then?

    This is the method it should be hitting when using the Unvalidated data input, but it would be interesting to see what happens with just the HttpRequest.

    Meanwhile, we'll get it running locally and see what is going on.

    Allan

  • samevedzisamevedzi Posts: 30Questions: 5Answers: 0

    Hi Allan,

    Thanks for the response.

    I have tried just response.Process(formData). It did not work.

    Thanks,
    ---Stephen

Sign In or Register to comment.