I am writing a windows application using C#. I have a requirement where the files uploaded into the windows form are to be saved into a network share but not all users can access the network share (\\FileServer\SharedFolder). Only one user ( FileWriter)has got read / write / execute permissions on this folder. The current user EmployeeUser does not have any permissions on this share. I have verified this by opening the Start->Run \\FileServer\SharedFolder. This gives a Access Denied error box.
I have used this example from SO Post, using the WNetAddConnection2
to connect with different credentials of FileWriter to save the file Sample.txt using File.Create. So far everything was OK.WNetCancelConnection2
is called, I have verified in the code debug, and the program exited. Now from the current user, I have opened StartMenu --> Run and typed the \\FileServer\SharedFolder and the share immediately opened even though the windows user is EmployeeUser. I have closed the explorer and after a few minutes (this changes randomly through attempts) I have opened the Start->Run \\FileServer\SharedFolder. Now it gives a Access Denied error box.
I am unable to understand this, Any help on this is much appreciated.
Now after the Access Denied box I run the program again with the same steps except that the Sample.txt (using File.Create) is silently Overwritten. Isn't it supposed to give a File Exists Error?