Click here to Skip to main content
11,565,743 members (45,401 online)

Sharepoint

 
AnswerRe: How to make a sharepoint page accessible to all and settings custom themes based on User Pin
ihoecken8-Nov-12 1:00
memberihoecken8-Nov-12 1:00 
GeneralRe: How to make a sharepoint page accessible to all and settings custom themes based on User Pin
balaji101022-Nov-12 1:21
memberbalaji101022-Nov-12 1:21 
AnswerRe: How to make a sharepoint page accessible to all and settings custom themes based on User Pin
ihoecken8-Nov-12 1:08
memberihoecken8-Nov-12 1:08 
GeneralRe: How to make a sharepoint page accessible to all and settings custom themes based on User Pin
ihoecken8-Nov-12 2:01
memberihoecken8-Nov-12 2:01 
GeneralRe: How to make a sharepoint page accessible to all and settings custom themes based on User Pin
balaji101011-Nov-12 23:58
memberbalaji101011-Nov-12 23:58 
GeneralRe: How to make a sharepoint page accessible to all and settings custom themes based on User Pin
ihoecken12-Nov-12 0:17
memberihoecken12-Nov-12 0:17 
GeneralRe: How to make a sharepoint page accessible to all and settings custom themes based on User Pin
balaji101012-Nov-12 0:41
memberbalaji101012-Nov-12 0:41 
Question[SOLVED] Unable to add webpart to page from script, but successfull from command line using same code Pin
_HawkeyeD5-Nov-12 9:41
member_HawkeyeD5-Nov-12 9:41 
I am writing a script that will allow us to build an entire SharePoint environment, add solutions and implement web parts on particular pages from scratch. Nearly the entire script works except the last couple of lines which add the web parts to a page (of course). Here's the thing that is really weird. If I run the exact same code in a power-shell command line it works every time. The script that adds the web part to a page is called from a separate ps1 file that passes in the necessary information for the script to run. Here's the code:

function addWebPartToPage($siteURL, $pageURL, $webpartName, $listName, $solutionName, $destinationZone, $zoneIndex)
{
 
$web = Get-SPWeb $siteURL
$file = $web.GetFile($pageURL)
 
if($file.Exists)
{
    try
    {
        checkOutPage($file)
        $list = $web.Lists[$listName]
        $wpManager = $web.GetLimitedWebPartManager($web.Url + $pageURL,[System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared);
        $webPartListItem = $list.Items | where {$_.Title -eq $solutionName}
        $xmlReader = New-Object System.Xml.XmlTextReader($webPartListItem.File.OpenBinaryStream());
        $errorMsg = ""
 
        //breaks here:           
        $webPart = $wpManager.ImportWebPart($xmlReader, [ref]$errorMsg)
        $wpManager.AddWebPart($webpart,"$destinationZone",$zoneIndex)
 
    }
    catch
    {
        $ErrorMessage = $_.Exception.Message    
        $returnVal = 1          
    }
    finally
    {
        checkInPage($file)
 
        $pweb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
        $page = $pweb.GetPublishingPage($pageURL)
        approvePage $page
 
        #close the xml reader
        if($xmlReader -ne $null)
        {
            $xmlReader.Close()
        }
 
        $wpManager.Dispose()
        $web.Dispose()
 
        [GC]::Collect()     
        checkIfFailed $returnVal
    }
}

To prove the code actually worked, I opened a new PowerShell window with Admin rights (note the window that is calling the script itself is also using admin rights) and set the above variables to the values that would be passed in. I then copied and pasted my code block into the window and it ran successfully (WAT???).
So this has myself and a colleague completely stumped. Why does it work inside a script window as a code block, but won't run when I execute as a script. The error I receive is this:

An error occurred adding webpart Poll to the page Pages/WebpartTest.aspx. Error: Exception calling "ImportWebPart" with "2" argument(s): "A Web Part or Web Form Control on this Page cannot be displayed or imported. The type is not registered as safe."

I would look to this being a config issue (safeExecute in the config etc) if it wasn't for the fact that it runs successfully via VS2010 and in a code block rather than through a script. All other functionalities of my script work including adding and activating solutions, creating Site Collections, etc.

Any help or input would be greatly appreciated.

Thank you.

modified 9-Nov-12 12:31pm.

AnswerRe: Unable to add webpart to page from script, but successfull from command line using same code Pin
ihoecken6-Nov-12 2:05
memberihoecken6-Nov-12 2:05 
GeneralRe: Unable to add webpart to page from script, but successfull from command line using same code Pin
_HawkeyeD6-Nov-12 4:04
member_HawkeyeD6-Nov-12 4:04 
AnswerRe: Unable to add webpart to page from script, but successfull from command line using same code Pin
_HawkeyeD9-Nov-12 6:30
member_HawkeyeD9-Nov-12 6:30 
QuestionAdding users to the default members group Pin
Aptiva Dave1-Nov-12 8:17
memberAptiva Dave1-Nov-12 8:17 
AnswerRe: Adding users to the default members group Pin
ihoecken4-Nov-12 20:54
memberihoecken4-Nov-12 20:54 
GeneralRe: Adding users to the default members group Pin
balaji10108-Nov-12 0:12
memberbalaji10108-Nov-12 0:12 
AnswerRe: Adding users to the default members group Pin
ihoecken8-Nov-12 0:21
memberihoecken8-Nov-12 0:21 
GeneralRe: Adding users to the default members group Pin
balaji10108-Nov-12 0:33
memberbalaji10108-Nov-12 0:33 
AnswerRe: Adding users to the default members group Pin
ihoecken8-Nov-12 0:36
memberihoecken8-Nov-12 0:36 
QuestionSharePoint Standard 2007 to SharePoint 2007 Enterprise Pin
fmorales0931-Oct-12 10:24
memberfmorales0931-Oct-12 10:24 
AnswerRe: SharePoint Standard 2007 to SharePoint 2007 Enterprise Pin
ihoecken4-Nov-12 20:48
memberihoecken4-Nov-12 20:48 
QuestionNot been able to log into SharePoint site after deploying new WSP Pin
NetMan201229-Oct-12 22:21
memberNetMan201229-Oct-12 22:21 
AnswerRe: Not been able to log into SharePoint site after deploying new WSP Pin
ihoecken29-Oct-12 23:06
memberihoecken29-Oct-12 23:06 
AnswerRe: Not been able to log into SharePoint site after deploying new WSP Pin
arunkumaryoyo31-Oct-12 19:52
memberarunkumaryoyo31-Oct-12 19:52 
Questionshare document can detete by only who can uploaded not to others Pin
HemadriT26-Oct-12 5:19
memberHemadriT26-Oct-12 5:19 
AnswerRe: share document can detete by only who can uploaded not to others Pin
ihoecken28-Oct-12 22:35
memberihoecken28-Oct-12 22:35 
GeneralRe: share document can detete by only who can uploaded not to others Pin
HemadriT1-Nov-12 4:53
memberHemadriT1-Nov-12 4:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web03 | 2.8.150624.2 | Last Updated 17 Jun 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid