C# - I/O on the network

Asked

Viewed 700 times

0

I have a program that makes I/O files (create, edit, save), but I need to put it to do this I/O with files that are on the company network, both read and write.

My question is: My program needs permission to read and write files, or the program user who needs these permissions on his machine to network?

If it is the user who needs to have this permission, I can put the address of the network server on Path what use to save program files? Or something else is needed?

If it is permission of my program, written in C#, it is necessary what exactly?

  • You’ve already tested to see what happens?

  • Not yet friend @Laerte, I still do not have access to the network, I wanted to confirm this before requesting access.

2 answers

3


My program needs permission to read and write files, or the program user who needs these permissions on his or her network machine?

Who needs to have read/write permission is the user and not the application.

If it is the user who needs to have this permission, can I put the address of the network server in the Path that I use to save the program files? or something more is needed?

Yes, you should use the network path as if it were a local path. It’s all the same.


Of course there may be some restrictions that invalidate what was said above, but as there are no further details, there is no way to be sure.

  • Thank you, I will request the network ip and test.

2

Come on, your program about running under a user authentication, always. With this in mind it is easy to understand that this user should yes have access to the file you want to open via app.

However, not always the same user that runs your app is the same who will access the file remotely. You can have a unique file access account.

For this case, you can use the technique of impersonate. I found this file in en Working with Impersonate and Web. In the end you’ll do something like this:

using (ImpersonateConnection)
{
    // Este trecho de código irá rodar sob outro usuário
    var file = File.OpenRead(@"\\Servidor\PastaCompartilhada\arquivo.txt");
    // ... outra coisas
}
  • legal Thiago, I will study about it and decide with the team which is the best approach, thanks for the help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.