使用api问题将文件或文件夹移动到google文档中的其他文件夹

时间:2010-12-17 01:40:42

标签: c# .net google-code google-docs-api google-docs

在Google文档中,我有一个结构:

Folder1
+------Folder1-1
+------+------File1-1-1
+------Folder1-2
+------File1-1
Folder2

我想移动" File1-1"到" Folder2"使用.Net google api库(Google Data API SDK

public static void moveFolder(string szUserName, string szPassword, string szResouceID, string szToFolderResourceID)
    {
        string szSouceUrl = "https://docs.google.com/feeds/default/private/full"
            + "/" + HttpContext.Current.Server.UrlEncode(szResouceID);
        Uri sourceUri = new Uri(szSouceUrl);
        //create a atom entry
        AtomEntry atom = new AtomEntry();
        atom.Id = new AtomId(szSouceUrl);


        string szTargetUrl = "http://docs.google.com/feeds/default/private/full/folder%3Aroot/contents/";
        if (szToFolderResourceID != "")
        {
            szTargetUrl = "https://docs.google.com/feeds/default/private/full"
            + "/" + HttpContext.Current.Server.UrlEncode(szToFolderResourceID)
            + "/contents"
            ;
        }
        Uri targetUri = new Uri(szTargetUrl);


        DocumentsService service = new DocumentsService(SERVICENAME);
        ((GDataRequestFactory)service.RequestFactory).KeepAlive = false;
        service.setUserCredentials(szUserName, szPassword);

        service.EntrySend(targetUri, atom, GDataRequestType.Insert);


    }

运行此功能后我有:

Folder1
+------Folder1-1
+------+------File1-1-1
+------Folder1-2
+------File1-1
Folder2
+------File1-1

" File1-1"显示在" Folder1"和" Folder2",当我从文件夹中删除它时,它将被删除在另一个文件夹中。 (期望:" File1-1"仅显示在" Folder2")

会发生什么?我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

根据protocol docs,这似乎是一个两步过程。将File1-1放入Folder2,然后从Folder1中删除文件File1-1。这不起作用吗?

有趣的是,3.0 Python API使其成为一个步骤。