How do I get a single files name from a get request using the drive api?
I have made a request but there is not metadata about the file there, I can only download it.
var fileId = "0BwwA4oUTeiV1UVNwOHItT0xfa2M";
var request = driveService.Files.Get(fileId);
Apparently this return a files.get in the response according to this doc
I just want to download a file and have its name displayed, not just its id
For Google Drive V3:
C#:string f = driveService.Files.Get(fileId).Execute().Name;
VB:Dim f As String = driveService.Files.Get(fileId).Execute().Name
You can get the file name from the Title
property in the File
class:
string FileName = service.Files.Get(FileId).Execute().Title;
and for downloading,
// DriveService _service: a valid Authendicated DriveService
// Google.Apis.Drive.v2.Data.File _fileResource: Resource of the file to download. (from service.Files.Get(FileId).Execute();)
// string _saveTo: Full file path to save the file
public static void downloadFile(DriveService _service, File _fileResource, string _saveTo)
{
if (!String.IsNullOrEmpty(_fileResource.DownloadUrl))
{
try
{
var x = _service.HttpClient.GetByteArrayAsync(_fileResource.DownloadUrl);
byte[] arrBytes = x.Result;
System.IO.File.WriteAllBytes(_saveTo, arrBytes);
}
catch(Exception e)
{
MessageBox.Show(e.Message, "Error Occured", MessageBoxButtons.OK, MessageBoxIcon.Error);
Environment.Exit(0);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With