Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [HttpPost]
- public ActionResult ShowExcelFile(HttpPostedFileBase getFile)
- {
- //Make something with values of getFile
- return PartialView("ShowExcelFile");
- }
- @using (Html.BeginForm("ShowExcelFile", "ShowExcel", FormMethod.Post, new { enctype = "multipart/form-data" }))
- {
- <input type="file" id="getFile" name="getFile" /><br />
- <input type="submit" value="Upload file" />
- }
- using Excel;
- [HttpPost]
- public ActionResult ShowExcelFile(HttpPostedFileBase getFile)
- {
- if (getFile != null && getFile.ContentLength > 0)
- {
- // .xlsx
- IExcelDataReader reader = ExcelReaderFactory.CreateOpenXmlReader(getFile.InputStream);
- // .xls
- IExcelDataReader reader = ExcelReaderFactory.CreateBinaryReader(getFile.InputStream);
- reader.IsFirstRowAsColumnNames = true; // if your first row contains column names
- }
- return PartialView("ShowExcelFile");
- }
- DataSet dataSet = reader.AsDataSet();
- @using (Html.BeginForm("ShowExcelFile", "ShowExcel", FormMethod.Post, new { enctype = "multipart/form-data" }))
- {
- @Html.TextBoxFor(m => m.Files, new { type = "file", name = "Files" })<br />
- <input type="submit" value="Upload file" />
- }
- public class AModel
- {
- public AModel()
- {
- Files = new List<HttpPostedFileBase>();
- }
- public List<HttpPostedFileBase> Files { get; set; }
- // Rest of model details
- }
- [HttpPost]
- public ActionResult ShowExcelFile(AModel model)
- {
- var file = model.Files[0];
- ...
- }
- string fileExtension = Path.GetExtension(getFile.FileName);
- //save this file using
- string path = Path.Combine(Server.MapPath(Url.Content("~/Content")), "Name"+fileExtension);
- file.SaveAs(path);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement