I am writing a program that reads through a .CSV file that is located in a shared folder on a network. I am currently logged onto my computer with a user that can access this folder, so I can run the program without any issues. However, the program will be used by someone who doesn't have access to the folder, and so my colleague created a user with the credentials, for example, username:user1 and password:pass1 that the program should use to access the shared folder.
I would like to ask if someone knows how to implement this, that is, use the user my colleague created to access the shared folder, look for a specific file, and read through it line by line.
I emphasize that I only need to read the files, and not write in them.
Below is a part of the code that I use when reading from the file. Mind you that this is not all of the code; it only shows the parts where I am accessing the file or reading from it.
/* Directory location of the file */
var directory = new DirectoryInfo(@"\\Network\\Folder");
/* Get the latest available file */
file = (from f in directory.GetFiles()
orderby f.LastWriteTime descending
select f).First();
var reader = new StreamReader(File.OpenRead(file.FullName),
Encoding.GetEncoding("iso-8859-1"));
string line;
/* Read through it line by line */
while (!reader.EndOfStream)
{
line = reader.ReadLine();
}