I have a file share on a remote PC, read only, guest access is on. I'm trying to read a file from that share via its UNC path, from a desktop app, using the code like this: var bytes = File.ReadAllBytes(@"\\someservser\someshare\somefile.txt");
, but getting the following exception:
System.IO.IOException
HResult=0x80070569
Message=Logon failure: the user has not been granted the requested logon type at this computer.
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>
This exception was originally thrown at this call stack:
System.IO.__Error.WinIOError(int, string) in __error.cs
System.IO.FileStream.Init(string, System.IO.FileMode, System.IO.FileAccess, int, bool, System.IO.FileShare, int, System.IO.FileOptions, Microsoft.Win32.Win32Native.SECURITY_ATTRIBUTES, string, bool, bool, bool) in filestream.cs
System.IO.FileStream.FileStream(string, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, int, System.IO.FileOptions, string, bool, bool, bool) in filestream.cs
System.IO.File.InternalReadAllBytes(string, bool) in file.cs
I can open this file from Windows UI without any problem (same user as used to run the failing app).
Any ideas?
you can try the approach below (with credentials)
using (new NetworkConnection(@"\\someservser\someshare", readCredentials)){
var s = File.ReadAllBytes(@"\\server\read\file\somefile.txt");
}
and check this address for NetworkConnection implementation
EDIT: for the "Logon failure: the user has not been granted the requested logon type at this computer.” error, try the steps below
On the Telnet server, open the Group Policy Management Editor. To do so, click Start, then in the Start Search box, type gpedit.msc, and then press ENTER.
If the User Account Control dialog box appears, confirm that the action it displays is what you want, and then click Continue.
In the navigation pane, open Computer Configuration, Windows Settings, Security Settings, Local Policies, and User Rights Assignment.
In the details pane, double-click Allow log on locally.
Click Add User or Group.
another option is to give access to everyone user so that you won't need to login.
but again the best way is to create a local account for this particular purpose
User contributions licensed under CC BY-SA 3.0