public ActionResult UploadOutSubmit(HttpPostedFileBase file2)
{
if (file2 != null && file2.ContentLength > 0)
{
var fileName = Path.GetFileName(file2.FileName);
var path = Path.Combine(Server.MapPath("/images/"), fileName);
file2.SaveAs(path);//save file to path /images/
//if you would like to save file to database,you should add in model Model model= new Model(); model.xxx="xx"; model.fileName="~/images/" + fileName; ... db.Tables.Add(model); db.SaveChanges();
}
return View();
}
In addition,the other way to read json file in controller,you could refer to this link:
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
23 Points
157 Posts
Read the uploaded json file
Jan 17, 2019 06:50 PM|slkim|LINK
I want to upload the json file stored in my computer and read the data value of the uploaded json file.
Contributor
3540 Points
905 Posts
Re: Read the uploaded json file
Jan 17, 2019 08:36 PM|l.laxmikant|LINK
Try below code
Contributor
3710 Points
1431 Posts
Re: Read the uploaded json file
Jan 18, 2019 09:13 AM|Yuki Tao|LINK
Hi slkim,
1.read the data value of the uploaded json file,you could refer to this demo:
https://jsfiddle.net/Ln37kqc0/
Javascript:
View:
2.And then based on 1,you could add action code in back end to save file which has been uuploaded:
Controller:
In addition,the other way to read json file in controller,you could refer to this link:
https://forums.asp.net/p/2147069/6230491.aspx?Re+Saving+data+to+the+json+file
Best Regards.
Yuki Tao
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.