last day (15 days later) » 

2:33 PM
0
Q: How to get webPart XML with powershell from SharePoint WebPart Gallery

GoshkyI want to get web part XML from SharePoint Web Parts Gallery(not locally) for add webpart into a List page. This is my code: $spWeb = Get-SPWeb $webURL $spSiteCollection = Get-SPWeb -Identity $spWeb.Site.Url $pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($spSiteCo...

 
Modify this line as $webPartFile = $spWeb.GetFile($wpl.File) and check
Sorry modified comment, it should be $webPartFile = $spWeb.GetFile($wpl.File) , missed adding the $
 
Seen my updated question
sharepoint.stackexchange.com/questions/233319/… Result from this accepted answer is the same.
 
Sorry, i dont understand. The error is gone, right ? What's the issue ? not able to add webpart ?
 
I want to get xml of file FundGHGEditForm.webpart and pass to = $wpManager.ImportWebPart($xmlReader, [ref]$errorMsg)
Hello
Are you there?
 
hey, yes i am !
 
2:35 PM
1
A: How to add webPart to Page with PowerShell from WebPart Gallery

Gautam ShethYou can try and modify the below PS script: #ensure that you use the site collection root url #if you use subsite url, will throw error since webpart gallery #exists only in the site collection root site $web = Get-SPWeb "https://site-collection-url" $pubWeb = [Microsoft.SharePoint.Publishin...

Your code from this post, doest working
 
so whats the issue here ?
ok checking
 
$xmlReader = New-Object System.Xml.XmlTextReader($wpl.File.OpenBinaryStream());
Cannot get correct XML of web part
Variable return this:
 
ok got it wait :)
 
A want to get correct XML like this:
<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="PLVDigitalLirex.PrimaryFundGHGEditForm.PrimaryFundGHGEditForm, PLVDigitalLirex, Version=1.0.0.0, Culture=neutral, PublicKeyToken=38f44e6a41d214c2" />
<importErrorMessage>$Resources:core,ImportErrorMessage;</importErrorMessage>
</metaData>
<data>
<properties>
<property name="Title" type="string">PLVDigitalLirex - PrimaryFundGHGEditForm</property>
<property name="Description" type="string">My Visual Web Part</property>
Thanks :)
 
ok so in your code can you pass the $webPartName = "PLVDigitalLirex - PrimaryFundGHGEditForm" and then check ?
 
2:39 PM
Moment
 
Something like

$spWeb = Get-SPWeb $webURL
$spSiteCollection = Get-SPWeb -Identity $spWeb.Site.Url
$webPartName = "PLVDigitalLirex - PrimaryFundGHGEditForm"

$pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($spSiteCollection)
$pageName = "$pageName.aspx"
$list = $spWeb.Lists[$listName]
$publishingPage = $list.RootFolder.Files | where {$_.Name -eq $pageName}
$publishingPage.CheckOut();

$webPartslist = $spSiteCollection.Lists["Web Part Gallery"]

#use the webpart title or the .webpart file name
 
Seen this
 
Can you try this ?

$spWeb = Get-SPWeb $webURL
$spSiteCollection = Get-SPWeb -Identity $spWeb.Site.Url

$webPartName = "PLVDigitalLirex - PrimaryFundGHGEditForm"

$pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($spSiteCollection)
$pageName = "$pageName.aspx"
$list = $spWeb.Lists[$listName]
$publishingPage = $list.RootFolder.Files | where {$_.Name -eq $pageName}
$publishingPage.CheckOut();

$webPartslist = $spSiteCollection.Lists["Web Part Gallery"]

#use the webpart title or the .webpart file name
there ?
any luck ?
 
2:56 PM
HEre
MOment
 
3:09 PM
There?
 
any luck ?
??
yes here
 
I'm here
script is bigger
500 rows of code
Who create web application, site collection, subsites, lists, content types
and need a time for execute
sorry for waiting
 
hey no worries
just use the snippet I posted
for test purposes
hey out to fetch milk , will be back in few mins
also, you can try with this code, if something doesnt work at your end :)
$Url = $(Read-Host -Prompt "Enter site url:")
$web = Get-SPWeb $Url
$web.AllowUnsafeUpdates=$true

function Add-WebPartToPage($pageUrl, $webpartzone,$index,$fileName)
{
    $webPartGallery = $web.Lists["Web Part Gallery"]

    Write-Host "Searching webpart $fileName in web part gallery" -ForegroundColor Yellow
    if($webPartGallery -eq $null)
    {
        Write-Host("Unable to retrieve Webpartgallery");
    }
    $webpart = $null;
    $webpart=$webPartGallery.Items | ? { $_.Title -eq $fileName}
 
My business logic need to add web part in List Page
When i try to open Any forms of list with this code
I have following errors:
Translation:

Unfortunately something went wrong
The file can not be found.

Web Components Support Page: If you have permissions, you can use this page to temporarily disable web components or remove personal settings. For more information, contact the site administrator.
 
3:33 PM
ok not sure why its not working
$Url = $(Read-Host -Prompt "Enter site url:")
$web = Get-SPWeb $Url
$web.AllowUnsafeUpdates=$true

function Add-WebPartToPage($pageUrl, $webpartzone,$index,$fileName)
{
    $webPartGallery = $web.Lists["Web Part Gallery"]

    Write-Host "Searching webpart $fileName in web part gallery" -ForegroundColor Yellow
    if($webPartGallery -eq $null)
    {
        Write-Host("Unable to retrieve Webpartgallery");
    }
    $webpart = $null;
    $webpart=$webPartGallery.Items | ? { $_.Title -eq $fileName}
this is production working code :)
can you please just replace the page name and site collection url and try ?
 
THis is code where add webpart intro a Page from Library
i need code where add webpart intro List (AddForm, EditForm, DisplayForm)
This way is different
 
yes
can you try it ?
 
Write me a code that adds a webpart to a list page in my post and I will be very grateful to you!
 
just modify this code :)
change the page name , site collection and webpart name
 
This code does not work because it adds a webpart to a regular page rather than a list page.
unction AddingWebPartToPage($webURL, $listName, $pageName, $webPartName){
#ensure that you use the site collection root url
#if you use subsite url, will throw error since webpart gallery
#exists only in the site collection root site

$GC = Start-SPAssignment

$spWeb = Get-SPWeb $webURL
$spSiteCollection = Get-SPWeb -Identity $spWeb.Site.Url

$webPartName = "PLVDigitalLirex - PrimaryFundGHGEditForm"

$pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($spWeb)
$pageName = "$pageName.aspx"
Where is the difference ?
 
3:44 PM
the difference is quite stark :)
Add-WebPartToPage "$SiteURL/Pages/$PageName"
 
only this $list = $spWeb.Lists[$listName]
$publishingPage = $list.RootFolder.Files | where {$_.Name -eq $pageName}
 
here pass the the add new form url
no have changed it entirely
not using publishing page at all
publishing web
 
Тханкс..
 
any luck ?
 

last day (15 days later) »