Class FilesResource
The "files" collection of methods.
Inherited Members
Namespace: Google.Apis.Drive.v2
Assembly: Google.Apis.Drive.v2.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 the specified file.
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 to copy. |
Returns
Type | Description |
---|---|
FilesResource.CopyRequest |
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 to delete. |
Returns
Type | Description |
---|---|
FilesResource.DeleteRequest |
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 insert 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 for the file in question. |
Returns
Type | Description |
---|---|
FilesResource.GetRequest |
Insert(File)
Inserts 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.insert
must specify the MIME
type application/vnd.google-apps.shortcut
. Apps should specify a file extension in the title
property
when inserting files with the API. For example, an operation to insert a JPEG file should specify something
like "title": "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.InsertRequest Insert(File body)
Parameters
Type | Name | Description |
---|---|---|
File | body | The body of the request. |
Returns
Type | Description |
---|---|
FilesResource.InsertRequest |
Insert(File, Stream, string)
Inserts 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.insert
must specify the MIME
type application/vnd.google-apps.shortcut
. Apps should specify a file extension in the title
property
when inserting files with the API. For example, an operation to insert a JPEG file should specify something
like "title": "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.InsertMediaUpload Insert(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.InsertMediaUpload |
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
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 |
Patch(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 change automatically, such as modifiedDate. This method supports patch semantics.
Declaration
public virtual FilesResource.PatchRequest Patch(File body, string fileId)
Parameters
Type | Name | Description |
---|---|---|
File | body | The body of the request. |
string | fileId | The ID of the file to update. |
Returns
Type | Description |
---|---|
FilesResource.PatchRequest |
Touch(string)
Set the file's updated time to the current server time.
Declaration
public virtual FilesResource.TouchRequest Touch(string fileId)
Parameters
Type | Name | Description |
---|---|---|
string | fileId | The ID of the file to update. |
Returns
Type | Description |
---|---|
FilesResource.TouchRequest |
Trash(string)
Moves a file to the trash. The currently authenticated user must own the file or be at least a
fileOrganizer
on the parent for shared drive files.
Declaration
public virtual FilesResource.TrashRequest Trash(string fileId)
Parameters
Type | Name | Description |
---|---|---|
string | fileId | The ID of the file to trash. |
Returns
Type | Description |
---|---|
FilesResource.TrashRequest |
Untrash(string)
Restores a file from the trash. The currently authenticated user must own the file or be at least a
fileOrganizer
on the parent for shared drive files.
Declaration
public virtual FilesResource.UntrashRequest Untrash(string fileId)
Parameters
Type | Name | Description |
---|---|---|
string | fileId | The ID of the file to untrash. |
Returns
Type | Description |
---|---|
FilesResource.UntrashRequest |
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 to update. |
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 to update. |
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 for the file in question. |
Returns
Type | Description |
---|---|
FilesResource.WatchRequest |