pnp / PnP-Sites-Core

Microsoft 365 Dev PnP Core component (.NET) targeted for increasing developer productivity with CSOM based solutions.
Other
416 stars 643 forks source link

Missing Document Library in page.InstantiateDefaultWebPart(DefaultClientSideWebParts #2180

Open anandasanyal opened 5 years ago

anandasanyal commented 5 years ago

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.

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

Thanks for your contribution! Sharing is caring.

heinrich-ulbricht commented 5 years ago

@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.

anandasanyal commented 5 years ago

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

heinrich-ulbricht commented 5 years ago

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.

anandasanyal commented 5 years ago

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 notifications@github.com 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

heinrich-ulbricht commented 5 years ago

@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.

anandasanyal commented 5 years ago

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 notifications@github.com 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 commented 5 years ago

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

heinrich-ulbricht commented 5 years ago

@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.)

anandasanyal commented 5 years ago

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 notifications@github.com 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

oliverlp commented 4 years ago

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