Click here to Skip to main content
15,910,471 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How to access / read remote location files using c#?
Posted

You get an Access Denied message because the user account your ASP.NET code runs under does not have permissions to access any network shares.

Go into IIS Manager, into the Application Pool that is running your code and change the account it's using.

You have to use some domain account where your IIS server AND the server hosting the share that you want to get to trusts. Usually, the machines and user account are in the same domain. This user account must be specifically setup with permissions to access the network share and login as a service.
 
Share this answer
 
Access it via a UNC.

C#
System.IO.FileStream stream = System.IO.File.OpenRead("\\servername\sharename\path\file.txt");


If this code is running under asp.net then you'll need to change the anonymous user account to a domain account that has the desired access as the default account can't access the network.
 
Share this answer
 
Comments
vaibhav10Dec1987 22-Jan-16 5:51am    
Hi,
Thanks for reply.
But While accessing that remote location I got an error "Access to the path <Path_Name> is denied."
F-ES Sitecore 22-Jan-16 5:53am    
As I said, you need to make sure the anonymous user account is one that has access to the share. Normal windows authentication rules still apply.

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