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

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 !

Related

How to get all Data Objects related to Asset in Pimcore?

I need to get all Data Objects related to Asset.
I can't find it in Asset API documentation: https://pimcore.com/docs/pimcore/current/Development_Documentation/Assets/Working_with_PHP_API.html
How to do it the most efficient way?
You can see and debug how it is used in Pimcore Admin Panel on 'Requires' Tab of Asset:
$dependencies = $asset->getDependencies()->getRequiredBy();
foreach ($dependencies as $dependency) {
if ($dependency['type'] !== 'object') {
continue;
}
$concreteDataObject = Concrete::getById($dependency['id']);
}

Equivalent of "UserProperties" property in Azure.Messaging.ServiceBus SDK

I am trying to migrate from the Legacy Azure service bus SDK to the new one "Azure.Messaging.ServiceBus". I don't see the equivalent of the "UserProperties" property with the new Azure.Messaging.ServiceBus.ServiceBusMessage. Where can I set the user properties? I see a property called "ApplicationProperties". Is that the one to go for?
Microsoft.Azure.ServiceBus.Message msg = new Microsoft.Azure.ServiceBus.Message(Encoding.UTF8.GetBytes(message.Body));
if (message.Headers != null)
{
foreach (KeyValuePair<string, object> item in message.Headers)
{
msg.UserProperties.Add(item.Key, item.Value); //I need help for this statement.
}
}
Yes, ApplicationProperties is the new custom headers collection to use.

When trying to get all webparts on a Sharepoint Online page using C# CSOM, I get 0 returned (while there *are* webparts on my page)

So I'm using C# CSOM code to try and get all webparts, so that I can remove one. My Sharepoint Online page is just a standard modern teamsite page with nothing changed yet. I want to get all webparts, then remove the quick links standard webpart using csom. Here's my code:
Microsoft.SharePoint.Client.File oFile =
Context.Web.GetFileByServerRelativeUrl("/sites/CR-WST-GYM-20130306/SitePages/Home.aspx");
LimitedWebPartManager wpManager = oFile.GetLimitedWebPartManager(PersonalizationScope.Shared);
/*Context.Load(wpManager.WebParts,
wps => wps.Include(
wp => wp.WebPart.Title));*/
Context.Load(wpManager);
Context.ExecuteQueryRetry();
WebPartDefinitionCollection wpDefinitionCollection = wpManager.WebParts;
Context.Load(wpDefinitionCollection);
Context.ExecuteQueryRetry();
It loads, but wpManager.WebParts contains 0 values & has a count of 0... how is this possible, when there's already standard webparts added to a newly created teamsite? Shouldn't I get at least a couple? What might I be doing wrong?
This code is taken from: https://learn.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/ee539301(v%3Doffice.14) .
EDIT: I've also added a new webpart via UI to my main page to see if I get "1" as value, but it's still 0 ...
For "modern" site pages OfficeDevPnP.Core.Pages namespace has been introduced to manage web parts instead of Microsoft.SharePoint.Client.WebParts namespace
The following example demonstrates how to retrieve the list of client-side web parts on page
using (var ctx = new ClientContext(webUrl))
{
ctx.Credentials = GetCredentials(userName, password);
var page = OfficeDevPnP.Core.Pages.ClientSidePage.Load(ctx, "Home.aspx");
var webParts = page.Controls.Where(c => c.Type.Name == "ClientSideWebPart").ToList();
}
Prerequisites
SharePointPnPCoreOnline package
Reference
Customizing "modern" site pages
PnP isn't needed. This is working for me.
CamlQuery allPagesQuery = new CamlQuery();
ListItemCollection pageItems = list.GetItems(allPagesQuery);
ctx.Load(pageItems, pi => pi.Include(i => i.Id, i => i.DisplayName));
ctx.ExecuteQuery();
foreach (var item in pageItems)
{
ctx.Load(item, i => i.File, i => i.File.ServerRelativeUrl);
ctx.ExecuteQuery();
LimitedWebPartManager wpManager =
item.File.GetLimitedWebPartManager(PersonalizationScope.Shared);
ctx.Load(wpManager, wpm => wpm.WebParts.Include(wp => wp.WebPart.Title, wp => wp.Id));
ctx.ExecuteQuery();
foreach (WebPartDefinition wp in wpManager.WebParts)
{
log4.DebugFormat("Webpart in {0}: {1} [{2}]",
item.File.ServerRelativeUrl, wp.WebPart.Title, wp.Id);
}
}

Binary content(BLOB) of files uploaded in sharepoint Document Library?

From initial R & D , I got to know that files are not physically located in Sharepoint .
Where(table field) is the binary content of Files uploaded in Document library located in SQL Server ?
There is a table 'AllDocStream' and View 'DocStream' with field named 'content' with Binary values . But I don't find corresponding File IDs etc for the record in those table and View.
What is the way if I want to access the binary content of files uploaded in Document Library ?
I want to use those binary content of files in some other application to for display/view/download of file .
Thanks and in advance .
If you can get to the SPFile object the SharePoint C# API then you could use the code from the answer to this other question.
using (SPSite site = new SPSite(siteUrl))
{
using (SPWeb web = site.RootWeb)
{
SPList list = web.Lists["Document Library Name"];
foreach (SPListItem item in list.Items)
{
SPFile file = item.File;
using (Stream stream = file.OpenBinaryStream())
{
//Do what you want with the Stream...
}
}
}
}

How do I perform a MOSS FullTextSqlQuery and filter people results by the Skills managed property?

I am having trouble with a MOSS FulltextSqlQuery when attempting to filter People results on the Skills Managed Property using the CONTAINS predicate. Let me demonstrate:
A query with no filters returns the expected result:
SELECT AccountName, Skills
from scope()
where freetext(defaultproperties,'+Bob')
And ("scope" = 'People')
Result
Total Rows: 1
ACCOUNTNAME: MYDOMAIN\Bob
SKILLS: Numchucks | ASP.Net | Application Architecture
But when I append a CONTAINS predicate, I no longer get the expected result:
SELECT AccountName, Skills
from scope()
where freetext(defaultproperties,'+Bob')
And ("scope" = 'People')
And (CONTAINS(Skills, 'Numchucks'))
Result
Total Rows: 0
I do realize I can accomplish this using the SOME ARRAY predicate, but I would like to know why this is not working with the CONTAINS predicate for the Skills property. I have been successful using the CONTAINS predicate with a custom crawled property that is indicated as 'Multi-valued'. The Skills property (though it seems to be multi-valued) is not indicated as such on the Crawled Properties page in the SSP admin site:
http:///ssp/admin/_layouts/schema.aspx?ConsoleView=crawledPropertiesView&category=People
Anyone have any ideas?
So with the help of Mark Cameron (Microsoft SharePoint Developer Support), I figured out that certain managed properties have to be enabled for full text search using the ManagedProperty object model API by setting the FullTextQueriable property to true. Below is the method that solved this issue for me. It could be included in a Console app or as a Farm or Web Application scoped Feature Receiver.
using Microsoft.Office.Server;
using Microsoft.Office.Server.Search.Administration;
private void EnsureFullTextQueriableManagedProperties(ServerContext serverContext)
{
var schema = new Schema(SearchContext.GetContext(serverContext));
var managedProperties = new[] { "SKILLS", "INTERESTS" };
foreach (ManagedProperty managedProperty in schema.AllManagedProperties)
{
if (!managedProperties.Contains(managedProperty.Name.ToUpper()))
continue;
if (managedProperty.FullTextQueriable)
continue;
try
{
managedProperty.FullTextQueriable = true;
managedProperty.Update();
Log.Info(m => m("Successfully set managed property {0} to be FullTextQueriable", managedProperty.Name));
}
catch (Exception e)
{
Log.Error(m => m("Error updating managed property {0}", managedProperty.Name), e);
}
}
}
SELECT AccountName, Skills
from scope()
where freetext(defaultproperties,'+Bob')
And ("scope" = 'People')
And (CONTAINS(Skills, 'Numchucks*'))
use the * in the end.
You also have a few more options to try:
The following list identifies
additional query elements that are
supported only with SQL search syntax
using the FullTextSqlQuery class:
FREETEXT()
CONTAINS()
LIKE
Source

Resources