日期:2014-05-16  浏览次数:20443 次

uploadfy导入Excel内容到数据库中2
cs:(上传文件并将Excel中的内容导入到数据库中)
public JsonResult DoImport(string uploadtype, string q_t)
        {
            iPAL.Applications.Authen.LoginUser user = (iPAL.Applications.Authen.LoginUser)(Session["LoginUser"]);
            m_userno = user.WorkNo;

            AjaxCallResult result = new AjaxCallResult();

            HttpContext.Response.ContentType = "text/plain";
            HttpContext.Response.Charset = "utf-8";

            string msg = string.Empty;
            string strUploadPath = HttpContext.Request.PhysicalApplicationPath + "iPALUploads\\";
            try
            {
                if (!Directory.Exists(strUploadPath))
                {
                    Directory.CreateDirectory(strUploadPath);
                }
                if ( HttpContext.Request.Files.Count != 1 )
                {
                    result.result = -1;
                    result.data = "上传文件只能为1.";
                    return Json(result);
                }
                HttpPostedFileBase postedFile = HttpContext.Request.Files[0];
                string fileName = postedFile.FileName;
                string ext = fileName.Substring(fileName.LastIndexOf('.'));
                string tempFile = fileName.Substring(0,fileName.Length - ext.Length -1 ) +  Guid.NewGuid().ToString("N");
                tempFile = Path.Combine(strUploadPath, tempFile) + ext;
                postedFile.SaveAs(tempFile);

                result.result = ImportSheet(tempFile, q_t, m_userno, ref msg);
                result.data = msg;

            }
            catch (Exception ex)
            {