1
Answer

Access a file on local area network with authorization

Hi. Firstly, I apologize to you for my poor english.
 
I want to access a file on a different machine that is on the same network as me. I also need to authenticate when doing this.
 
For Example;
 
My Local IP : 10.1.1.138
 
Target Local IP: 10.1.1.235
 
File Location is \\10.1.1.235\FolderName\example.txt
 
Username for target machine is: "username"
 
Password for target machine is: "password"
 
I want to do like this:
 
string data = File.GetAllText(@"\\10.1.1.235\FolderName\example.txt"); //with authentication
 
How can I do?
Answers (1)
1
Sameer Shaik

Sameer Shaik

NA 953 1k 7y
Here is the sample code (not tested)
 
//Get all config files from directory 
string[] files = Directory.GetFiles (sourceDirectory, "*.config")
loop through each file, 
Read file line by line 
 
var fileStream = new FileStream(@"c:\file.config", FileMode.Open, FileAccess.Read);
using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
{
string line;
while ((line = streamReader.ReadLine()) != null)
{
// process the line
if(line.contains("endpoint"))
{
//process ur end point here
}
}
}
 
0
Chitra

Chitra

NA 7 240 7y
Thanks Sameer, but can you please help me with the code.
0
Sameer Shaik

Sameer Shaik

NA 953 1k 7y
first you need to find/prepare regular expression for endpoint string format.
Later you can read text of each file and find the matching text