0

有以下网址

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

我需要发送对该项目的父 URL 的请求(在此特定情况下为图像)并获得响应:

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

如果使用 CSOM 或 Office 365 活动 API,是否存在此类请求?我在哪里可以找到这样的例子?

4

1 回答 1

0
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;
        }
于 2017-06-28T13:52:05.533 回答