コード例 #1
0
        public JsonResult Upload()
        {
            object obj = null;
            Dictionary <string, object> jo = new Dictionary <string, object>();

            //## 如果有任何檔案類型才做
            if (Request.Files.AllKeys.Any())
            {
                //## 讀取指定的上傳檔案ID
                var httpPostedFile = Request.Files["UploadedImage"];
                var isHeader       = Request.Form["isHead"];
                var importStartRow = Request.Form["importStartRow"];
                //## 真實有檔案,進行上傳
                if (httpPostedFile != null && httpPostedFile.ContentLength != 0)
                {
                    var fileName = Path.GetFileName(httpPostedFile.FileName);
                    var path     = Path.Combine(Server.MapPath("~/FileUploads"), fileName);
                    httpPostedFile.SaveAs(path);
                    jo.Add("result", true);
                    ExcelTool exceltool = new ExcelTool();
                    obj = exceltool.ExcelToJson(path, isHeader, importStartRow);
                    //jo.Add("result", obj);
                }
            }
            JsonResult jOBJ = Json(obj);

            return(Json(obj));
        }