Class FilesResource
The "files" collection of methods.
Inherited Members
Namespace: Google.Apis.Drive.v3
Assembly: Google.Apis.Drive.v3.dll
Syntax
public class FilesResource
Constructors
FilesResource(IClientService)
Constructs a new resource.
Declaration
public FilesResource(IClientService service)
Parameters
Type | Name | Description |
---|---|---|
IClientService | service |
Methods
Copy(File, string)
Creates a copy of a file and applies any requested updates with patch semantics.
Declaration
public virtual FilesResource.CopyRequest Copy(File body, string fileId)
Parameters
Type | Name | Description |
---|---|---|
File | body | The body of the request. |
string | fileId | The ID of the file. |
Returns
Type | Description |
---|---|
FilesResource.CopyRequest |
Create(File)
Creates a new file. This method supports an /upload URI and accepts uploaded media with the following
characteristics: - Maximum file size: 5,120 GB - Accepted Media MIME types:*/*
Note: Specify a valid
MIME type, rather than the literal */*
value. The literal */*
is only used to indicate that any valid
MIME type can be uploaded. For more information on uploading files, see Upload file
data. Apps creating shortcuts with files.create
must specify the MIME
type application/vnd.google-apps.shortcut
. Apps should specify a file extension in the name
property
when inserting files with the API. For example, an operation to insert a JPEG file should specify something
like "name": "cat.jpg"
in the metadata. Subsequent GET
requests include the read-only fileExtension
property populated with the extension originally specified in the title
property. When a Google Drive user
requests to download a file, or when the file is downloaded through the sync client, Drive builds a full
filename (with extension) based on the title. In cases where the extension is missing, Drive attempts to
determine the extension based on the file's MIME type.
Declaration
public virtual FilesResource.CreateRequest Create(File body)
Parameters
Type | Name | Description |
---|---|---|
File | body | The body of the request. |
Returns
Type | Description |
---|---|
FilesResource.CreateRequest |
Create(File, Stream, string)
Creates a new file. This method supports an /upload URI and accepts uploaded media with the following
characteristics: - Maximum file size: 5,120 GB - Accepted Media MIME types:*/*
Note: Specify a valid
MIME type, rather than the literal */*
value. The literal */*
is only used to indicate that any valid
MIME type can be uploaded. For more information on uploading files, see Upload file
data. Apps creating shortcuts with files.create
must specify the MIME
type application/vnd.google-apps.shortcut
. Apps should specify a file extension in the name
property
when inserting files with the API. For example, an operation to insert a JPEG file should specify something
like "name": "cat.jpg"
in the metadata. Subsequent GET
requests include the read-only fileExtension
property populated with the extension originally specified in the title
property. When a Google Drive user
requests to download a file, or when the file is downloaded through the sync client, Drive builds a full
filename (with extension) based on the title. In cases where the extension is missing, Drive attempts to
determine the extension based on the file's MIME type.
Declaration
public virtual FilesResource.CreateMediaUpload Create(File body, Stream stream, string contentType)
Parameters
Type | Name | Description |
---|---|---|
File | body | The body of the request. |
Stream | stream | The stream to upload. See remarks for further information. |
string | contentType | The content type of the stream to upload. |
Returns
Type | Description |
---|---|
FilesResource.CreateMediaUpload |
Remarks
Considerations regarding stream
:
-
If
stream
is seekable, then the stream position will be reset to0
before reading commences. Ifstream
is not seekable, then it will be read from its current position -
Caller is responsible for maintaining the
stream
open until the upload is completed - Caller is responsible for closing the
stream
Delete(string)
Permanently deletes a file owned by the user without moving it to the trash. If the file belongs to a shared
drive, the user must be an organizer
on the parent folder. If the target is a folder, all descendants
owned by the user are also deleted.
Declaration
public virtual FilesResource.DeleteRequest Delete(string fileId)
Parameters
Type | Name | Description |
---|---|---|
string | fileId | The ID of the file. |
Returns
Type | Description |
---|---|
FilesResource.DeleteRequest |
Download(string)
Downloads content of a file. Operations are valid for 24 hours from the time of creation.
Declaration
public virtual FilesResource.DownloadRequest Download(string fileId)
Parameters
Type | Name | Description |
---|---|---|
string | fileId | Required. The ID of the file to download. |
Returns
Type | Description |
---|---|
FilesResource.DownloadRequest |
EmptyTrash()
Permanently deletes all of the user's trashed files.
Declaration
public virtual FilesResource.EmptyTrashRequest EmptyTrash()
Returns
Type | Description |
---|---|
FilesResource.EmptyTrashRequest |
Export(string, string)
Exports a Google Workspace document to the requested MIME type and returns exported byte content. Note that the exported content is limited to 10MB.
Declaration
public virtual FilesResource.ExportRequest Export(string fileId, string mimeType)
Parameters
Type | Name | Description |
---|---|---|
string | fileId | The ID of the file. |
string | mimeType | Required. The MIME type of the format requested for this export. |
Returns
Type | Description |
---|---|
FilesResource.ExportRequest |
GenerateIds()
Generates a set of file IDs which can be provided in create or copy requests.
Declaration
public virtual FilesResource.GenerateIdsRequest GenerateIds()
Returns
Type | Description |
---|---|
FilesResource.GenerateIdsRequest |
Get(string)
Gets a file's metadata or content by ID. If you provide the URL parameter alt=media
, then the response
includes the file contents in the response body. Downloading content with alt=media
only works if the file
is stored in Drive. To download Google Docs, Sheets, and Slides use
files.export
instead. For more information, see Download
& export files.
Declaration
public virtual FilesResource.GetRequest Get(string fileId)
Parameters
Type | Name | Description |
---|---|---|
string | fileId | The ID of the file. |
Returns
Type | Description |
---|---|
FilesResource.GetRequest |
List()
Lists the user's files. This method accepts the q
parameter, which is a search query combining one or
more search terms. For more information, see the Search for files &
folders guide. Note: This method returns all files by default,
including trashed files. If you don't want trashed files to appear in the list, use the trashed=false
query parameter to remove trashed files from the results.
Declaration
public virtual FilesResource.ListRequest List()
Returns
Type | Description |
---|---|
FilesResource.ListRequest |
ListLabels(string)
Lists the labels on a file.
Declaration
public virtual FilesResource.ListLabelsRequest ListLabels(string fileId)
Parameters
Type | Name | Description |
---|---|---|
string | fileId | The ID for the file. |
Returns
Type | Description |
---|---|
FilesResource.ListLabelsRequest |
ModifyLabels(ModifyLabelsRequest, string)
Modifies the set of labels applied to a file. Returns a list of the labels that were added or modified.
Declaration
public virtual FilesResource.ModifyLabelsRequest ModifyLabels(ModifyLabelsRequest body, string fileId)
Parameters
Type | Name | Description |
---|---|---|
ModifyLabelsRequest | body | The body of the request. |
string | fileId | The ID of the file to which the labels belong. |
Returns
Type | Description |
---|---|
FilesResource.ModifyLabelsRequest |
Update(File, string)
Updates a file's metadata and/or content. When calling this method, only populate fields in the request
that you want to modify. When updating fields, some fields might be changed automatically, such as
modifiedDate
. This method supports patch semantics. This method supports an /upload URI and accepts
uploaded media with the following characteristics: - Maximum file size: 5,120 GB - Accepted Media MIME
types:*/*
Note: Specify a valid MIME type, rather than the literal */*
value. The literal */*
is only
used to indicate that any valid MIME type can be uploaded. For more information on uploading files, see
Upload file data.
Declaration
public virtual FilesResource.UpdateRequest Update(File body, string fileId)
Parameters
Type | Name | Description |
---|---|---|
File | body | The body of the request. |
string | fileId | The ID of the file. |
Returns
Type | Description |
---|---|
FilesResource.UpdateRequest |
Update(File, string, Stream, string)
Updates a file's metadata and/or content. When calling this method, only populate fields in the request
that you want to modify. When updating fields, some fields might be changed automatically, such as
modifiedDate
. This method supports patch semantics. This method supports an /upload URI and accepts
uploaded media with the following characteristics: - Maximum file size: 5,120 GB - Accepted Media MIME
types:*/*
Note: Specify a valid MIME type, rather than the literal */*
value. The literal */*
is only
used to indicate that any valid MIME type can be uploaded. For more information on uploading files, see
Upload file data.
Declaration
public virtual FilesResource.UpdateMediaUpload Update(File body, string fileId, Stream stream, string contentType)
Parameters
Type | Name | Description |
---|---|---|
File | body | The body of the request. |
string | fileId | The ID of the file. |
Stream | stream | The stream to upload. See remarks for further information. |
string | contentType | The content type of the stream to upload. |
Returns
Type | Description |
---|---|
FilesResource.UpdateMediaUpload |
Remarks
Considerations regarding stream
:
-
If
stream
is seekable, then the stream position will be reset to0
before reading commences. Ifstream
is not seekable, then it will be read from its current position -
Caller is responsible for maintaining the
stream
open until the upload is completed - Caller is responsible for closing the
stream
Watch(Channel, string)
Subscribes to changes to a file.
Declaration
public virtual FilesResource.WatchRequest Watch(Channel body, string fileId)
Parameters
Type | Name | Description |
---|---|---|
Channel | body | The body of the request. |
string | fileId | The ID of the file. |
Returns
Type | Description |
---|---|
FilesResource.WatchRequest |