Link to home
Start Free TrialLog in
Avatar of Dinesh Kumar
Dinesh KumarFlag 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.
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?
Avatar of 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
You first need to find out if server1 and 2 are visible to each other.
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.
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.
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.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thank you, will get back on this because I need permission to create shared folder.