Skip to content

Latest commit

 

History

History
90 lines (58 loc) · 2.4 KB

File metadata and controls

90 lines (58 loc) · 2.4 KB

SharedDriveConnection NuGet Package

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.

Getting Started

Installation

To use this library, you can install it via NuGet Package Manager Console:

Install-Package SharedDriveConnection

Usage

  1. 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
    }
  2. Dispose of the Connection:

    The connection will be automatically disposed of when leaving the using block. However, you can manually dispose of it using the Dispose method:

    driveConnect.Dispose();

Documentation

DriveConnect Class

Constructors

  • DriveConnect(string networkName, NetworkCredential credentials): Initializes a new instance of the DriveConnect class.

Events

  • Disposed: Occurs when the instance has been disposed.

Methods

  • Dispose(): Performs tasks associated with freeing, releasing, or resetting unmanaged resources.

Objects needed for Win32 functions

  • NetResource: Represents details of the proposed connection.
  • ResourceScope: Enumerates the resource scope.
  • ResourceType: Enumerates the resource type.
  • ResourceDisplaytype: Enumerates the resource display type.

Example

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

Contributions are welcome! Feel free to submit issues or pull requests.

License

This library is licensed under the MIT License.