Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);

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.
Posted
Updated 2-Sep-10 0:45am
v2

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


inside your asp.net page's code behind.
 
Share this answer
 
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.
 
Share this answer
 
v2
Comments
Dalek Dave 2-Sep-10 10:38am    
Good Answer
Al-Farooque Shubho 2-Sep-10 10:43am    
Thanks, mate.
you need setting access right for folder

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900