I'm trying to create a new directory tree on a network path.
The share is located at \\192.168.5.193\FileContext and has Everyone full access permissions.
This piece of code:
DirectoryInfo directoryInfo = Directory.
CreateDirectory(#"\\192.168.5.193\FileContext\FileContext_Root\General\Test");
gives me:
An exception of type 'System.IO.IOException' occurred in mscorlib.dll
but was not handled in user code
Additional information: Logon failure: unknown user name or bad password.
If I try to open the same address with Windows Explorer, it opens up without password requirements.
The CreateDirectory() documentation states it should accept UNC paths:
You can create a directory on a remote computer, on a share that you have write access to. UNC paths are supported; for example, you can specify the following for path: \2009\Archives\December in Visual Basic, and \\2009\Archives\December in C#.
It also states that IOExceptions could came from:
The directory specified by path is a file .
-or-
The network name is not known.
https://msdn.microsoft.com/en-us/library/vstudio/54a0at6s(v=vs.100).aspx
How can I resolve?
Starting from #JamesThorpe comment:
Everyone isn't Everyone
I came to the solution, just by adding the remote computer to the company domain.
With this action, it's not even necessary to add local computer's NETWORK SERVICE to remote folder's permissions.
Related
I have been trying to launch text pad installation from network path to a remote machine using WMI managementclass.InvokeMethod.
However several attempts have failed with
error code 1602
So I created a batch file containing script to launch installation executable from network path in a remote machine, and tried to invoke it with managementclass.InvokeMethod.
However, even this didn't work.
I tried the same by changing the executable from network path to remote machine C:\path.
And it worked!!!
But I want to launch the installation executable from a network path.
I would be grateful if somebody would help me.
I have a C# application that gets a list of directories inside a folder. This is done using the call
String[] projects = System.IO.Directory.GetDirectories("path/to/folder", "*", System.IO.SearchOption.TopDirectoryOnly);
This works fine on my machine, but after publishing (resulting in a setup.exe, as well as programName.application + Application Files) I tried running the program on a new machine and it threw an unhandled exception error.
The error was in regards to being unable to connect to a database, but the interesting part is that it was complaining about path not being valid, listing a path that only exists on my machine.
Does System.IO.Directory.GetDirectories not get reinitialized when running on another machine?
I guess the problem is with path/to/folder, as that path might not exist in new machine. Don't hard-code the path. Instead read it from config file (app.config using ConfigurationManager).
Using IIS 7.5 .NET Framework 4. I have a web page that needs to access a SQL 2012 Filetable folder. In IIS, I set up the file table folder as a virtual directory & in the connection, I'm using my active directory account login as the account to "Connect as...". I'm able to access the FileTable folder in windows explorer by going to it's location:
\\computername\sqlexp2012\filetabledb\filetabletb_dir
In IIS, if I right click on the virtual folder, and then click Explore, it opens up a Windows Explorer instance & displays the files there (lots of PDF files).
However, if I try to access the virtual folder directly (http://localhost/virtualfoldername) by right-clicking & going to Manage Virtual Directory, or access it through a web page (http://mywebsite/vname) I get the following error.
Error Summary
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related
configuration data for the page is invalid.
Detailed Error Information
Module IIS Web Core
Notification BeginRequest
Handler Not yet determined
Error Code 0x80070032
Config Error
Config File
Requested URL http://localhost:80/virtualfoldername
Physical Path \computername\sqlexp2012\FileTableDB\FileTableTb_Dir
Logon Method Not yet determined
Logon User Not yet determined
Config Source
-1:
0:
If I go in to the Virtual Directory & go to Manage Virtual Directory --> Advanced Settings, I see the physical path to the SQL Filetable folder & Physical Path credentials. My user account is set up as dbo under Security --> Users. The IIS log file is not helpful, nor is anything in the Event Viewer.
Anything I've been able to find has said that it is likely permissions related, but using my account - which I know works, as far as accessing the file share via Windows Explorer - doesn't. Any thoughts welcome.
Thanks!
I am trying to use PrincipalContext to check if a local user group exists on a remote computer.
I am having problems with PrincipalContext:
PrincipalContext ctx = new PrincipalContext(ContextType.Machine, machine, null, ContextOptions.Negotiate)
It works in such scenarios:
local to local machine
local to virtual machine
domain machine to workgroup machine
However it doesn't work in opposite direction:
virtual machine to local host
workgroup machine to domain machine
I am getting these errors:
Unhandled Exception: System.IO.FileNotFoundException: The network path was not found.
Unhandled Exception: System.Runtime.InteropServices.COMException: The network path was not found.
The first exception is for virtual machine, second for workgroup machine.
All machines have user with the same name and password and the code was executed from that user.
How to solve this issue?
I found the answer. It looks that DirectoryServices doesn't work on remote Windows 7 or newer.
I guess when a computer is in a workgroup then it is local and we can connect and when it is in a domain then it is remote.
I followed steps described here:
System.IO.FileNotFoundException: The network path was not found. Exception while using DirectoryEntry object on windows 7
and here:
http://www.peppercrew.nl/index.php/2011/09/connect-to-remote-registry-fails-with-an-error-is-preventing-this-key-from-being-opened/
Enable File and Print sharing in the Firewall
Start the Remote Registry Service
Add remote user access to this registry entry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurePipeServers\winreg
However I can't change services and registry settings on production servers. I found such way to get group:
var server = new DirectoryEntry(string.Format("WinNT://{0},Computer", machine));
DirectoryEntry group = server.Children.Cast<DirectoryEntry>().Where(
d => d.SchemaClassName.Equals("Group") && d.Name.Equals("Administrators")
).Single<DirectoryEntry>();
I have a UNC folder added in my machine using "Add Network Places" option in "My Network Places" (XP).
I need to select the specific unc folder through my C# "folderBrowser Dialogue."
However,as unc path is password protected. While selecting the same,how can I prompt for userCredentials. can anyone have thoughts on this...
PInvoke to WNetAddConnection2 and pass the CONNECT_INTERACTIVE flag to allow the OS to pop a username/password prompt if necessary. You can get the PInvoke definition here.