Click here to Skip to main content
15,911,132 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear Sir,

i have using one code for open a file in remote pc.but that code is not working correctly.can you plz help me to solve this problem.

i wrote this code in button click.in below the display is multi column text box.also the variable ipaddress is the ip address of remote system.

What I have tried:

protected void hostfile_Click(object sender, EventArgs e)
  {
      try
      {
          string path = (@"\" + ipaddress + "\\C:\\Windows\\System32\\drivers\\etc\\hosts");
          display.Text = (File.ReadAllLines(path)).ToString();

      }
      catch { }

  }
Posted
Updated 17-Dec-17 2:58am

First, the UNC path you're using is not valid. You cannot use a drive letter specification in it, like \\192.168.0.0\C:\... The C: is not a valid share name.

You could use the admin share (C$), IF AND ONLY IF the account your code is running under on the local machines has admin permissions to the remote share.

Otherwise, the remote machine has to have a share set up to share the files you want and give that share appropriate permissions to the account your code is going to run under. This is a LOT easier to setup and manage in a domain environment than it is in a workgroup.

If you have no idea what I'm talking about, Google for "windows networking basic concepts" and start reading.
 
Share this answer
 
Almost certainly, you can't do it: security prevents that - and particularly with anything below the Windows folder!
In order to access the folder, it would have to be shared and you would have to provide appropriate credentials for the share when you accessed it, or when you set up a map to a network drive on your PC.

A "normal" PC will not have that folder (or any part of it's path) shared - and I'd view any application which tried to establish such a share on my computer with deep suspicion.

Imagine if you could access a remote hosts file: what is stopping malicious software from doing the same and altering it to benefit themselves?
 
Share this answer
 
Comments
Basil PP 17-Dec-17 4:09am    
sir,

is there any other method to open a file in one pc from another pc using static ip .i need this to be a web application.
OriginalGriff 17-Dec-17 4:52am    
No. For very good reasons: if you could do it, so could anyone else. And that means ransomware you don't even have to download to get infected by!
Dave Kreskowiak 17-Dec-17 11:35am    
A web application? That's not going to work at all. The web server account that's going to be running your code will never (and NEVER should!) have access to the shares on a client machine.
________________ 17-Dec-17 4:13am    
You can download file, then read it from local folder.
And fix second row - display.Text = File.ReadAllText(path);
Basil PP 18-Dec-17 4:20am    
can you plz provide the sample for downloading file from remote pc to local pc.

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