Reading a file on another server c#

Generally we do the following to read the file if that is on same server:

log = File.ReadAllText(@"C:\App_Data\kewl.log");


There is web service running on SERVER1. The requirement is that this web service should read a file which resides on SERVER2

SERVER1: web server
SERVER2: web service server

how can we make this happen in c# i.e. reading a file on different server.

please help in finding the steps or how to do it or any possible blockers.
Dinesh KumarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
Are they both on the same network?

server2 needs access to server1. Create a share on server1 and use this code;
log = File.ReadAllText(@"\\SERVER1\ShareName\App_Data\kewl.log");

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Karrtik IyerSoftware ArchitectCommented:
hi Dinesh,

your question is not very clear, I understand that from server 1 you want to read a file on server 2.
1> Are both server 1 and server 2 both web servers?
2> Or is that server 1 is web server while server 2 is just another machine in the network from where you want to read the file?
3> if answer to question 1 is yes, then does server 2 expose any web service to read the file and return it to server 1?
Dinesh KumarAuthor Commented:
on Server1, the webapplication is running

webapplication calls services to show data, those services are hosted on Server2

I don't know if SERVER1 and SERVER2 are on the same network or not.

so in short, SERVER2 wants to read the file from SERVER1
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Éric MoreauSenior .Net ConsultantCommented:
You first need to find out if server1 and 2 are visible to each other.
Karrtik IyerSoftware ArchitectCommented:
Does server 1 want to read from server 2 or server 2 from server 1?
Your question states server 1 wants to read a file from server 2 which exposes web services.
But your last comment states server 2 wants to read from server 1. Please clarify who is the consumer of the file and who produces the file.
As Eric suggested, first find out if from server 1 you can access server 2 or vice versa. you can ping for the ip address or host name and find out if they are visible to each other and in same network.

if file cannot be accessed via file share (network share) as suggested by Eric in his first comment then expose a service in server 2 that would read the necessary file and return it to server 1.
Dinesh KumarAuthor Commented:
let us say if Ping happens.. from SERVER2 to SERVER1

then that means both are visible to each other and do that also employ that SERVER2 has read access to SERVER1 or there should be some appId which will  have read access to that folder.

@Karrtik Iyer: I can not create service on webserver. we have separate server for webapp and service server.
Karrtik IyerSoftware ArchitectCommented:
Create a folder share with some file in it on one server and try to access it from other server like
\\server1\folder. And see if you can open the file inside the folder and view it's contents.
Éric MoreauSenior .Net ConsultantCommented:
from server2, is it possible to open Windows Explorer (not Internet Explorer) and have access to \\Server1\ShareName?
Dinesh KumarAuthor Commented:
thank you, will get back on this because I need permission to create shared folder.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.