谷歌浏览器与互联网浏览器:fileupload excel调试问题 [英] Google chrome vs internet explorer: fileupload excel debugging issue

查看:117
本文介绍了谷歌浏览器与互联网浏览器:fileupload excel调试问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string path = Server.MapPath(exclupload.PostedFile.FileName);
       string path1 = exclupload.PostedFile.FileName;
       //Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" file location"; Extended Properties=Excel 8.0;IMEX=1;HDR=yes
       //string constr = string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0 Xml;HDR=YES;""", _path);

       string excelConnectionString1 = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 8.0;";
       string excelConnectionString2 = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;";

       string ext = System.IO.Path.GetExtension(this.exclupload.PostedFile.FileName);


       if (ext == ".xls" | ext.Equals(".elsx"))//Excel 97-03
           {
           conStr = excelConnectionString1;

           }
       else (ext == ".xlsx")//Excel 07

           {
               conStr = excelConnectionString2;
           }
         
       }



       OleDbConnection excelConnection = new OleDbConnection(conStr);
       OleDbCommand cmd = new OleDbCommand("Select [Comment] from ["+ "Sheet1" +"]", excelConnection);
       OleDbDataAdapter adp = new OleDbDataAdapter("Select [Comment] from ["+ "Sheet1" +"]", excelConnection);
       excelConnection.Open();

       DataSet ds = new DataSet();
       adp.Fill(ds);
       DataTable dt = ds.Tables[0];





我的尝试:



开启调试上述代码以将excel数据上传到datatable我将获得Internet Explorer中的完整路径。

当我尝试在谷歌浏览器中调试相同的代码时我只发布文件名和

我应该如何处理这个问题?

它抛出错误。另外在Chrome中它没有取出工作表名称



我试过



What I have tried:

On Debugging the above code for uploading the excel data to datatable i am getting the full path in Internet explorer.
When i try to debug the same code in Google Chrome i get only file name posted and
How should i handle this issue?
It throws the error.Also In Chrome it is not taking the Sheet Name

I tried

OleDbCommand cmd = new OleDbCommand("Select [Comment] from [Sheet1]", excelConnection);





另外。请帮帮我。

如果Internet Explorer浏览器中的任何安全性更改,每个用户都需要在Internet Explorer中进行更改。



Also . Please help me out.
In case of any security changes in the Internet Explorer Browser do every user needs to make the change in their Internet Explorer.

推荐答案

string path = Server.MapPath(exclupload.PostedFile.FileName);





那不是'去上班。正如您发现不同的浏览器提供不同的路径值,但即使这是正确的原始文件路径,它也是客户端上的路径,因此在服务器上执行mappath是没有意义的。



您需要忘记路径,只需使用文件名(上面代码中的路径1)。如果你想从这个文件中读取,你需要将它保存在服务器驱动器的某个地方,并在该文件上做一个mappath。例如,您可以将上传的文件保存到



~ / App_Data



然后是通往文件将是





That isn't going to work. As you've discovered different browsers give different path values, but even if this is the proper original file path, it is the path on the client, so doing a mappath on the server is pointless.

You need to forget the path, just use the filename (path1 in your code above). If you want to read from this file you'll need to save it somewhere on the server's drive, and do a mappath on that file. So for example you could save the uploaded file to

~/App_Data

then the path to the file would be

Server.MapPath("~/App_Data/" + path1);





从您发布的代码中,您似乎没有将文件保存在任何地方,因此这是您需要添加的步骤。



From the code you have posted you don't seem to be saving the file anywhere so that's a step you need to add.


这篇关于谷歌浏览器与互联网浏览器:fileupload excel调试问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆