SharedDriveConnection is a simple .NET library that facilitates connecting to a network share with authentication. This library provides a DriveConnect
class, allowing users to establish and manage network connections effortlessly.
To use this library, you can install it via NuGet Package Manager Console:
Install-Package SharedDriveConnection
-
Initialize DriveConnect:
using SharedDriveConnection;
// Specify the network share path and credentials string networkPath = "\\server\\share"; NetworkCredential credentials = new NetworkCredential("username", "password"); // Create an instance of DriveConnect using (DriveConnect driveConnect = new DriveConnect(networkPath, credentials)) { // Your code here }
-
Dispose of the Connection:
The connection will be automatically disposed of when leaving the
using
block. However, you can manually dispose of it using theDispose
method:driveConnect.Dispose();
DriveConnect(string networkName, NetworkCredential credentials)
: Initializes a new instance of theDriveConnect
class.
Disposed
: Occurs when the instance has been disposed.
Dispose()
: Performs tasks associated with freeing, releasing, or resetting unmanaged resources.
NetResource
: Represents details of the proposed connection.ResourceScope
: Enumerates the resource scope.ResourceType
: Enumerates the resource type.ResourceDisplaytype
: Enumerates the resource display type.
using SharedDriveConnection;
// Specify the network share path and credentials
string networkPath = "\\server\\share";
NetworkCredential credentials = new NetworkCredential("username", "password");
// Create an instance of DriveConnect
using (DriveConnect driveConnect = new DriveConnect(networkPath, credentials))
{
// Your code here
}
For more details on the Win32 functions used, refer to the Microsoft documentation.
Contributions are welcome! Feel free to submit issues or pull requests.
This library is licensed under the MIT License.