通过fileupload控件读取错误 [英] FIle reading error by fileupload control

查看:66
本文介绍了通过fileupload控件读取错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用fileupload控件,我打开一个excel文件并通过OleDbDataAdapter读取所有列和行并将值更新到数据库。当我运行应用程序时,它在本地主机中工作正常。但是如果我在服务器或IIS中托管应用程序,那么在尝试通过OleDbDataAdapter读取它时会出现错误。它说文件找不到。但我通过fileupload控件打开excel文件。我猜测fileupload控件返回的文件路径不是正确的路径。我必须添加服务器路径以获取完整路径。这是对的吗?

请告诉我。并且还请提供示例代码来获取它。

Hi

I am using fileupload control and i am opening a excel file and reading all the columns and rows through OleDbDataAdapter and updating the values to database. When i run the application it works fine in local host. But if i host the application in a server or in IIS then i get an an error when try to read it by OleDbDataAdapter. It says file is not found. But i open the excel file through the fileupload control. What i guess is that the filepath which is returned by the fileupload control is not the correct path. I have to add the server path to that to get the complete path. Is this correct?
Please let me know. and also please provide the sample code to get that.

推荐答案

C#代码在服务器上运行,而不是在客户端上运行。因此,您需要在服务器上提供两件事来读取Excel文件:.XLS(或类似)文件本身,以及Office可再发行组件或Excel副本。



当您在本地计算机上运行它时,它似乎都可以工作,因为客户端和服务器是同一台计算机。当你在生产中运行时,客户端和服务器可能相隔数千英里!



除非您的服务器可以访问您的应用程序通过OleDB使用的Excel代码你把文件放到服务器上,你不能用它做任何有用的事情......
C# code runs on the server, not the client. So there are two things you need to have available on the server to read the Excel file: the .XLS (or similar) file itself, and the Office redistributable or a copy of Excel.

When you run this on your local machine, it all appears to work because the client and the server are the same machine. When you run it in production, the client and server may be thousands of miles apart!

Unless your server has access to the Excel code your app is using via OleDB and you put the file onto the server, you can't do anything useful with it...


我解决了我的自我。只需将它保存到服务器中的某个位置然后再次获取它从该位置再次被system.io文件方法删除。
I solved it my self.just save it to a location in the server and then again fetch it from that location and again delete it by system.io file methods.


这篇关于通过fileupload控件读取错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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