Reading a file on another server c#

Dinesh Kumar
Dinesh Kumar used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior .Net Consultant
Top Expert 2016
Commented:
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

Karrtik IyerSoftware Architect

Commented:
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?

Author

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
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
You first need to find out if server1 and 2 are visible to each other.
Karrtik IyerSoftware Architect

Commented:
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.

Author

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 Architect

Commented:
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 Consultant
Top Expert 2016
Commented:
from server2, is it possible to open Windows Explorer (not Internet Explorer) and have access to \\Server1\ShareName?

Author

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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial