GoogleDrive

Connection and File Selection

WithCredentials authenticates the Drive connection using a Google service account or OAuth credentials built with GPAL.Credentials. WithLocalFile specifies a local GPALFile to upload. WithFileId targets a specific Drive file by its unique Google Drive file ID string. WithFileIds accepts an out IGPALGrid<string> parameter and populates it with file IDs from a list operation. ToGPALObject returns the IGoogleDrive interface.

NOTE

A Google Drive file ID is the alphanumeric string in the file URL: drive.google.com/file/d/FILE_ID_HERE/view. You can also retrieve file IDs by calling ListFiles after connecting.

Examples

GPAL Fluent: High-level fluent C# API

//Build the credentials object separately with GPAL.Credentials and pass it to WithCredentials. The same ICredentials object can be reused across GoogleDrive and GoogleSheets.

// Connect with a service account

var drive = GPAL.GoogleDrive

.WithCredentials(GPAL.CredentialsFor(CredentialServiceType.Google)

.WithUsername("you@example.com")

.WithPassword("your-password")

.WithServiceAccountKey((GPALFile)"service-account.json")

.WithScope(OAuthScope.Google_Drive)

.ToGPALObject())

.ToGPALObject();


// Target a file by ID

GPAL.GoogleDrive

.WithCredentials(googleCreds)

.WithFileId("1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgVE2upms")

.SaveTo("C:\Downloads\document.pdf");

💬 Ask GPAL