Avatar of Dinesh Kumar
Dinesh Kumar
Flag for India asked on

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");

Requirement:

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.
C#ASP.NETNetworking

Avatar of undefined
Last Comment
Dinesh Kumar

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Éric Moreau

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Karrtik Iyer

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 Kumar

ASKER
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
Éric Moreau

You first need to find out if server1 and 2 are visible to each other.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Karrtik Iyer

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 Kumar

ASKER
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 Iyer

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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Éric Moreau

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Dinesh Kumar

ASKER
thank you, will get back on this because I need permission to create shared folder.