PnP-Sites-Core icon indicating copy to clipboard operation
PnP-Sites-Core copied to clipboard

Missing Document Library in page.InstantiateDefaultWebPart(DefaultClientSideWebParts

Open anandasanyal opened this issue 5 years ago • 10 comments

Thank you for reporting an issue or suggesting an enhancement. We appreciate your feedback - to help the team to understand your needs, please complete the below template to ensure we have the necessary details to assist you. If you have a actual question, we would ask you to use SharePoint Developer Group at Microsoft Tech Community. Thanks!

Which PnP repository should you use to report the issue?

Please navigate to the appropriate repository by clicking on the link below and create your issue there. You can delete this section after you have navigated to the correct repository.

  • PnP Samples - https://github.com/OfficeDev/PnP
  • PnP Sites Core - https://github.com/OfficeDev/PnP-Sites-Core
  • PnP JS Core - https://github.com/OfficeDev/PnP-JS-Core
  • PnP PowerShell - https://github.com/OfficeDev/PnP-PowerShell

Category

[ ] Bug [ ] Enhancement

Environment

[ ] Office 365 / SharePoint Online [ ] SharePoint 2016 [ ] SharePoint 2013

If SharePoint on-premises, what's exact CU version:

Expected or Desired Behavior

If you are reporting a bug, please describe the expected behavior. If you are suggesting an enhancement please describe thoroughly the enhancement, how it can be achieved, and expected benefit.

Observed Behavior

If you are reporting a bug, please describe the behavior you expected to occur when performing the action. If you are making a suggestion, you can delete this section.

Steps to Reproduce

If you are reporting a bug please describe the steps to reproduce the bug in sufficient detail to allow testing. Only way to fix things properly, is to have sufficient details to reproduce it. If you are making a suggestion, you can delete this section.

Submission Guidelines

Delete this section after reading

  • All suggestions or bugs are welcome, please let us know what's on your mind.
  • If you are reporting any issues around PnP Core Component, please reproduce the issue with latest release.
  • If you are reporting issue around PnP Provisioning Engine, please share the xml template, if possible.
  • If you are reporting an issue around any of the samples, please ensure that you have clear reference on the sample and possibly code file, which should be fixed.
  • If you have a general question, please use the SharePoint Developer Group at Microsoft Tech Community.
  • Remember to include sufficient details and context.
  • If you have multiple suggestions or bugs please submit them in seperate bugs so we can track resolution.

Thanks for your contribution! Sharing is caring.

anandasanyal avatar Apr 17 '19 13:04 anandasanyal

@anandasanyal Could you please edit the ticket content and add more details about what you are trying to do, which results you observe and which results you expect? Especially the steps we can use to reproduce the issue are important.

heinrich-ulbricht avatar Apr 17 '19 14:04 heinrich-ulbricht

Hi, I'm trying to add a document library web-part in a modern page using CSOM, PnP. Here is my code.

var web = clientContext.Web; var page = clientContext.Web.AddClientSidePage("Home_Custom.aspx", true); CanvasSection section = new CanvasSection(page, CanvasSectionTemplate.TwoColumn, 10); page.Sections.Add(section); page.Save(); var wpExtDoc = page.InstantiateDefaultWebPart(DefaultClientSideWebParts.[DocumentEmbed/List/Image Gallery]); Document Library is missing. Although Document Library is available in web part gallery, which can be added manually. Am I missing something here. Any workaround/ resolution/ reference is highly appreciated.. Thank you

ananda

anandasanyal avatar Apr 17 '19 15:04 anandasanyal

You can add a list web part like this using PnP cmdlets:

Connect-PnPOnline https://<tenant>.sharepoint.com/sites/test
$page = Add-PnPClientSidePage -Name "Home_Custom.aspx" -Publish
$list = Get-PnPList "Shared Documents" # get your list here
Add-PnPClientSidePageSection -Page $page -SectionTemplate TwoColumn
Add-PnPClientSideWebPart -Page $page -DefaultWebPartType List -WebPartProperties @{isDocumentLibrary=$true; selectedListId=$list.Id} -Section 1 -Column 1

Hope this helps.

heinrich-ulbricht avatar Apr 17 '19 16:04 heinrich-ulbricht

Thank you for your response. Can't we do it in CSOM,?? As I'm doing it in a windows console application. Thank you ananda

On Wed, Apr 17, 2019 at 9:46 PM Heinrich Ulbricht [email protected] wrote:

You can add a list web part like this using PnP cmdlets:

Connect-PnPOnline https://.sharepoint.com/sites/test $page = Add-PnPClientSidePage -Name "Home_Custom.aspx" -Publish $list = Get-PnPList "Shared Documents" # get your list here Add-PnPClientSidePageSection -Page $page -SectionTemplate TwoColumn Add-PnPClientSideWebPart -Page $page -DefaultWebPartType List -WebPartProperties @{isDocumentLibrary=$true; selectedListId=$list.Id} -Section 1 -Column 1

Hope this helps.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SharePoint/PnP-Sites-Core/issues/2180#issuecomment-484158834, or mute the thread https://github.com/notifications/unsubscribe-auth/AchqQkRmHVgSgVz2GqKY_494C7RlAc8oks5vh0jPgaJpZM4c1CcE .

-- Thanks & Regards Ananda

anandasanyal avatar Apr 17 '19 16:04 anandasanyal

@anandasanyal Yes you can; I wasn't sure since you mentioned PnP. I would suggest searching for the implementation of the PnP cmdlets over here: https://github.com/SharePoint/PnP-PowerShell They are implemented using CSOM.

heinrich-ulbricht avatar Apr 17 '19 16:04 heinrich-ulbricht

I'm using using OfficeDevPnP.Core.Enums; using OfficeDevPnP.Core.Entities; using OfficeDevPnP.Core.Pages;

Searched Github, not found any. So thought to check in. anyways Thank you ananda

On Wed, Apr 17, 2019 at 9:56 PM Heinrich Ulbricht [email protected] wrote:

@anandasanyal https://github.com/anandasanyal Yes you can; I wasn't sure since you mentioned PnP. I would suggest searching for the implementation of the PnP cmdlets over here: https://github.com/SharePoint/PnP-PowerShell They are implemented using CSOM.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SharePoint/PnP-Sites-Core/issues/2180#issuecomment-484162715, or mute the thread https://github.com/notifications/unsubscribe-auth/AchqQsbVinK-7YzsrAKWgHYxxFb0yQp0ks5vh0sWgaJpZM4c1CcE .

-- Thanks & Regards Ananda

anandasanyal avatar Apr 17 '19 16:04 anandasanyal

Yes, you were correct. Here is my code.

var wpExtDoc = page.InstantiateDefaultWebPart(DefaultClientSideWebParts.List); wpExtDoc.Properties["isDocumentLibrary"] = true; wpExtDoc.Properties["Name"] = "Documents"; wpExtDoc.Properties["View"] = "All Documents"; wpExtDoc.Properties["Folder"]= "External Document Library"; page.AddControl(wpExtDoc, section.Columns[0]); page.Save(); page.Publish();

But still there are issues, I can only see the web part [library] when I edit the page, The web part does n't appear in normal mode. I had to edit and select the folder.

Any idea??

Thank you ananda

anandasanyal avatar Apr 18 '19 09:04 anandasanyal

@anandasanyal I had to set the property selectedListId to the ID of the list to show (Documents lib in your case). Try this instead of setting Name. (But I'm just guessing; PnP PowerShell sets the properties via webpart.PropertiesJson.)

heinrich-ulbricht avatar Apr 18 '19 10:04 heinrich-ulbricht

Hi Heinrich Thank you for your response. It was quite helpful. I'm having another issues, just checking if you can give a direction.

I'm trying add a SPFX webpart, in my new provisioned page. The webpart is already deployed. I can see that using AppManager(clientContext);

When I’m trying to get the app using, var components = page.AvailableClientSideComponents(); it’s not getting, as it’s in [Apps you can add] state, not in added state. Not appeared in Webpart gallery.

Once I add this, then it will appear in Webpart gallery. How to achieve this condition, automate the above state. Am I missing something here.

Any help on this is much appreciated.

Code:

var components = page.AvailableClientSideComponents();

//string wpName = "project-status-client-side-solution";

string wpName = "7fd19df0-1ec9-4fe8-9c7e-7812e5ef583a";

// Find our custom "project-status-client-side-solution" web part

List componentsnames = components.Select(k => k.Name).ToList();

var webPartToAdd = components.Where(wp => wp.ComponentType == 1 && wp.Name == wpName).FirstOrDefault();

            if (webPartToAdd != null) // always returning null

            {

                ClientSideWebPart clientWp = new

ClientSideWebPart(webPartToAdd) { Order = -1 };

                page.AddControl(clientWp);

            }

page.Save(); Checked with wp.Name and wp.Id, bot not worked..

Thank you anand

On Thu, Apr 18, 2019 at 3:40 PM Heinrich Ulbricht [email protected] wrote:

@anandasanyal https://github.com/anandasanyal I had to set the property selectedListId to the ID of the list to show. Try this instead of setting Name. (But I'm just guessing; PnP PowerShell sets the properties via webpart.PropertiesJson.)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SharePoint/PnP-Sites-Core/issues/2180#issuecomment-484437948, or mute the thread https://github.com/notifications/unsubscribe-auth/AHEGUQXTU3HUJMT5V3HD34LPRBCKNANCNFSM4HGUE4CA .

-- Thanks & Regards Ananda

anandasanyal avatar Apr 21 '19 13:04 anandasanyal

I got the same problem in the 3 tenants I checked this morning.

oliverlp avatar Sep 29 '20 10:09 oliverlp