C#读取Excel文件而不保存在服务器上 [英] C# Reading Excel File without saving on server

查看:337
本文介绍了C#读取Excel文件而不保存在服务器上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ExcelReaderFactory读取excel文件而不保存在服务器上,当我用VS运行代码(即Ctrl + F5)时,它工作正常,但是当我在服务器(甚至本地IIS)上发布它时,它会给出错误

I am using ExcelReaderFactory for reading excel file without saving on server, When I run the code with VS(ie Ctrl+F5) it works fine, but when I publish it on server(or even local IIS) it gives error

Access to the Path 'path of my file' is denied



以下是我的代码




Below is my code

public void UploadFile(HttpPostedFile file)
{
FileStream stream = File.Open(file.FileName, FileMode.Open, FileAccess.Read);
 IExcelDataReader excel= ExcelReaderFactory.CreateBinaryReader(stream);  

}





有人可以建议一些替代代码来实现这个吗?



Can anyone suggest some alternate code for implementing this?

推荐答案

错误很明显,这是一个权限问题。这意味着您需要查看托管站点的IIS中的应用程序池的标识,然后将该用户的写入权限授予您尝试保存文件的目录。
The error is clear, it's a permissions issue. This means you need to look at the identity of the application pool in IIS that is hosting your site and then grant write permissions to that user to the directory where you are trying to save the files.


在正常情况下,Web服务器不应该访问客户端的文件结构。

只是尝试可视化影响,如果此安全措施不到位。

任何网站你打开可以读取你机器上的所有文件。



最好的方法(如果你不想将文件存储在服务器上)是保存文件在网络服务器上,阅读然后将其删除。
In normal scenario, web server should not have access on client's file structure.
just try to visualize the implications, if this security measure is not in place.
Any website you may open could read all files on your machine.

the best possible approach (if you don't want to store the file on server) is to save the file on webserver, read it and then delete it.


这篇关于C#读取Excel文件而不保存在服务器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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