读取服务器文件 [英] read server file

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

问题描述

我在服务器内部创建了一个文件夹,现在我正在将文件复制到其中,我需要读取文件并根据其格式显示它.

我需要使用将其转换为字节

我可以做的

I have created folder in the server inside this i am copying files into it now i need to read file and show it according to its format.

i need to this using converting it into the bytes

that i can do

byte[] content = File.ReadAllBytes(path);


但是如何读取文件

我可以使用server.mappath.做到这一点,但它会在当前的Directoy下创建文件夹.

如何访问说一些路径D://Test Foleder(网站不在此文件夹下托管

我们可以这样做吗?


but how to read file

I can do this using server.mappath.but it creates folder under current directoy.

how to access say some path D://Test foleder(web site is not hosted under this folder

can we do this.

推荐答案

如果您已经知道路径,为什么需要sever.mappath,如果在尝试访问外部文件时却被拒绝访问webapplication文件夹,最可能是因为IIS在更安全的区域下运行.如果要查找服务器硬盘上托管网站的目录,请使用此属性

if you already know the path why is there a need for sever.mappath, if you are getting access denied while trying access files outside the webapplication folder, most likely its because IIS is run under a more secured zone. and if you are looking for the directory where the web site is hosted on the server''s hard disk use this property

Request.PhysicalApplicationPath



在您的asp.net页面的代码后面.



inside your asp.net page''s code behind.


我不确定我是否正确理解了您的问题.

假设您有一些文件udner D://Test文件夹,并且您的物理Web应用程序目录位于其他某个文件夹中(例如,C://web/myapp).

现在,您需要从Web应用程序中知道正确的文件路径,对吗?

如果是这样,则无法使用Server.MapPath() 进行此操作,因为此方法通过使用相对URL和应用程序文件夹的物理路径来构成物理路径.因此,如果文件位于Web应用程序文件夹中,则可以使用Server.MapPath().确定文件的物理位置,否则不可以.

就您而言,您可以在Web配置的<appsettings></appsettings>部分中维护文件夹路径,并且可以读取该配置值以构成文件Path.

假设您将directoy路径配置为D://Test
并且,您的文件名为Howto.doc

因此,您必须确定文件的物理路径(使用System.IO.Path.Combine()方法):D://Test/Howto.doc

希望对您有所帮助.
I am not sure whether I understood your problem correctly.

Assuming you have some files udner D://Test folder and your physical web application directory is in some other folder (Say, C://web/myapp).

Now, you need to know the correct file path from within your web application, right?

If that is so, you can''t do that using the Server.MapPath() because, this method constitutes the physical path by using the relative Url and the physical path of the application folder. So, if the file is within the web application folder, you can use Server.MapPath(). to determine the physical location of the file, otherwise not.

In your case, you can maintain the folder path in the <appsettings></appsettings> section of your web config and you can read that configuration value to constitute the file Path.

Suppose, you configured the directoy path as D://Test
And, your file name is Howto.doc

So, you have to determine the physical path of the file (Using System.IO.Path.Combine() method) : D://Test/Howto.doc

Hope that helps.


您需要为文件夹
设置访问权限
鼠标右键单击文件夹名称->属性->安全->添加NEWWORK SERVICE
you need setting access right for folder

mouse right click folder name -->property ->security -> ADD NEWWORK SERVICE


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

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