简体   繁体   English

如何在C#中使用Google Drive API为文件设置自定义文件属性

[英]how to set custom file properties for a file using google drive api in C#

I am trying to set some custom file properties to some files that I am uploading to google drive using the API. 我正在尝试将一些自定义文件属性设置为使用API​​上传到Google驱动器的某些文件。 I am doing this in dot net using C#. 我正在使用C#在点网中执行此操作。 I saw a sample code in the net as follows: 我在网上看到了一个示例代码,如下所示:

{
  'key':        'additionalID',
  'value':      '8e8aceg2af2ge72e78',
  'visibility': 'PRIVATE'
}

But this code is giving me compile error (Syntax error at ":"). 但是这段代码给了我编译错误(“:”处的语法错误)。 My code is below: 我的代码如下:

string myMimeType = GetMimeType(FileName);
System.IO.FileInfo info = new System.IO.FileInfo(FileName);
Google.Apis.Drive.v2.Data.File body = new Google.Apis.Drive.v2.Data.File();
     body.Title = info.Name;
     body.Description = info.Name;
     body.MimeType = myMimeType;
     body.Editable = false;
     body.Shared = true;
     body.Properties = new List<PropertyList>() {
                "key": "myspecialID",
                "value": "test123456",
                "visibility": "PUBLIC" };

Thanks. 谢谢。

By looking at the V2 API for File and Property it looks more like this is how you would add properties to File objects . 通过查看V2 API的文件属性 ,看起来更像是将属性添加到File objects The structure you saw on this page was just a psuedo outline of the properties. 您在此页面上看到的结构只是属性的伪轮廓。

body.Properties = new IList<Property>() {
    new Property() { Key = "myspecialID", Value = "test123456", Visibility = "PUBLIC" }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM