SharePoint 在线 (O365):如何获取父项目 URL?

SharePoint online (O365):How to get a parent item URL?

有以下URL

https://test.sharepoint.com/shared%20documents/MyFolder1/myImg1.jpeg

我需要发送此项目的父项 URL 的请求(在此特定案例图片中)并获得响应:

https://test.sharepoint.com/shared%20documents/MyFolder1/

如果使用 CSOM 或 Office 365 Activity API,是否存在此类请求? 我可以在文档中的什么地方找到这样的例子?

static public string ReturnFileParentUrl(string url)
        {
            try
            {
                Uri uri = new Uri("https://XXX.sharepoint.com/");
                using (var ctx = GetContext(uri, "YYY@DOMAIN.com", "password"))
                {

                    Microsoft.SharePoint.Client.File item = ctx.Web.GetFileByServerRelativeUrl(url);

                    ctx.Load(item);
                    ctx.ExecuteQuery();

                    Console.WriteLine("file: {0}\n", item.Name);
                    Console.WriteLine("Type: {0}\n", item.TypedObject.ToString());
                    if (item.TypedObject.ToString() == "Microsoft.SharePoint.Client.File") //To check if there is a better way to check if the item is a file 
                        if (item.ServerObjectIsNull != true)
                        {
                            ctx.Load(item, i => i.ListItemAllFields);
                            ctx.ExecuteQuery();
                            var folder = ctx.Web.GetFolderByServerRelativeUrl((string)item.ListItemAllFields["FileDirRef"]);
                            ctx.Load(folder);
                            ctx.ExecuteQuery();
                            Console.WriteLine("parent relative url {0}\n", folder.ServerRelativeUrl);
                            return folder.ServerRelativeUrl;
                        }

                    return null;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return null;
        }