Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

How to return a List, stored in a DocumentSet, based on the Current ListItem?

$
0
0

I have 2 ListItems, each has a DocumentSet with 2 documents each. I'm attempting to download only those Documents attached to the current ListItem.

This is my first time working with documentSets.

This is What I've tried

CamlQuery query = new CamlQuery
    {
        //<-- Returns only a Single file which is wrong
        ViewXml = "<View Scope='RecursiveAll'>" +"<Query>" +"<Where>" +"<Eq>" +"<FieldRef Name='ID'/>" +"<Value Type='Int'>" + Item["ID"] + "</Value>" +"</Eq>" +"</Where>" +"</Query>" +"</View>"

        // <--- Returns all 4 files which is wrong
        //ViewXml = @"<View Scope='RecursiveAll'>
        //         <Query>
        //            <Where>
        //                <Eq>
        //                   <FieldRef Name='FSObjType' />
        //                   <Value Type='int'>0</Value>
        //                 </Eq>
        //             </Where>
        //          </Query>
        //       </View>"
    };
    Web web = ctx.Web;
    Microsoft.SharePoint.Client.List list = web.Lists.GetByTitle(SharePointConnector.DocumentLibrary);
    ListItemCollection items = list.GetItems(query);
    ctx.Load(items, collection => collection.Include(i => i.File.ServerRelativeUrl, i => i.File.Name));

    try
    {
        ctx.ExecuteQuery();
    }
    catch (System.Exception ex)
    {
        Console.WriteLine(string.Format("SharePoint Communication error - Message: {0}\n", ex.Message));
        SharePointConnector.lstExceptions.Add(Utilities.Exception(Service.Type.Sharepoint, ex, null));
        Utilities.ShowEXITMessage();
    }

    return items.Select(i => i.File).ToList();


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>