1

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();
}
kayess
  • 3,384
  • 9
  • 28
  • 45
A. Daniel
  • 23
  • 5
  • Haven't tried it yet, but was looking at this as I need too will soon be doing some impersonation. http://stackoverflow.com/questions/125341/how-do-you-do-impersonation-in-net – TyCobb Jan 13 '17 at 15:57
  • the IT department cant provide an active directory read-only authorization to this folder for this users? is this a security issue? – Jonathan Applebaum Jan 13 '17 at 16:09

0 Answers0