David
David

Reputation: 117

PNP CORE SDK : How to get the file properties of a list item

Here is my request working with SHAREPOINT REST API:

_api/web/lists/getByTitle('Commercial')/Items?$expand=File&$select=Id,File/ServerRelativeUrl

I want to do the equivalent of this with PNP CORE SDK, I did this:

IList listCommercial = pnpCoreContextProject.Web.Lists.GetByTitle("Commercial");                                            
foreach (var item in listCommercial.Items.QueryProperties(
    i => i.File.QueryProperties(f => f.ServerRelativeUrl))
    ){
       Log(item.File.ServerRelativeUrl);
    }

and I get:

Property ServerRelativeUrl was not yet loaded: à PnP.Core.Model.TransientObject.GetValue[T](String propertyName) à PnP.Core.Model.SharePoint.File.get_ServerRelativeUrl()

Any idea why ? How should I do this ? Thanks !

Upvotes: 2

Views: 1103

Answers (1)

Zrethreal
Zrethreal

Reputation: 338

Not entirely sure, but it might be the nested QueryProperties that creates the issue. If you rewrite slightly it will work:

IList listCommercial = _pnpContext.Web.Lists.GetByTitle("Documents");
var files = listCommercial.RootFolder.Files.QueryProperties(f => f.ServerRelativeUrl);
foreach (var file in files)
{
    Console.WriteLine(file.ServerRelativeUrl);
}

Note that results will be paged so that you will only get the first 100 results unless you explicitly specify something else in your query

Upvotes: 0

Related Questions