MVC本地上传EXCEL并分析存入数据库正常,发布到IIS后报错:未在本地计算机上注册“Microsoft.Jet.Oledb.4.0。原因是VS调试时模拟的是32位,发布后的IIS是64位。
需要到IIS设置对应的应用池。将 高级设置中的 启用32位应用程序 从false改为true.
public string GetUploadPath(HttpPostedFileBase file)
{
string fileNameR;
string savePath;
if (file == null || file.ContentLength <= 0)
{
//ViewBag.error = "文件不能为空";
return null;
}
else
{
string filename = Path.GetFileName(file.FileName);
int filesize = file.ContentLength;//获取上传文件的大小单位为字节byte
string fileEx = Path.GetExtension(filename);//获取上传文件的扩展名
string NoFileName = Path.GetFileNameWithoutExtension(filename);//获取无扩展名的文件名
int Maxsize = 4000 * 1024;//定义上传文件的最大空间大小为4M
string FileType = ".xls,.xlsx";//定义上传文件的类型字符串
fileNameR = NoFileName +