Click here to Skip to main content
11,484,402 members (65,586 online)

Sharepoint

 
GeneralRe: configure sharepoint Pin
ihoecken13-Nov-12 22:17
memberihoecken13-Nov-12 22:17 
Questionhow to access sharepoint site by domain Pin
HemadriT12-Nov-12 10:19
memberHemadriT12-Nov-12 10:19 
AnswerRe: how to access sharepoint site by domain Pin
ihoecken12-Nov-12 22:29
memberihoecken12-Nov-12 22:29 
QuestionHow to customize sharepoint2010 Webpart style Pin
zhuwenli8-Nov-12 20:58
memberzhuwenli8-Nov-12 20:58 
AnswerRe: How to customize sharepoint2010 Webpart style Pin
ihoecken8-Nov-12 23:12
memberihoecken8-Nov-12 23:12 
QuestionHow to make a sharepoint page accessible to all and settings custom themes based on User Pin
balaji10108-Nov-12 1:37
memberbalaji10108-Nov-12 1:37 
AnswerRe: How to make a sharepoint page accessible to all and settings custom themes based on User Pin
ihoecken8-Nov-12 2:00
memberihoecken8-Nov-12 2:00 
GeneralRe: How to make a sharepoint page accessible to all and settings custom themes based on User Pin
balaji101022-Nov-12 2:21
memberbalaji101022-Nov-12 2:21 
AnswerRe: How to make a sharepoint page accessible to all and settings custom themes based on User Pin
ihoecken8-Nov-12 2:08
memberihoecken8-Nov-12 2:08 
GeneralRe: How to make a sharepoint page accessible to all and settings custom themes based on User Pin
ihoecken8-Nov-12 3:01
memberihoecken8-Nov-12 3:01 
GeneralRe: How to make a sharepoint page accessible to all and settings custom themes based on User Pin
balaji101012-Nov-12 0:58
memberbalaji101012-Nov-12 0:58 
GeneralRe: How to make a sharepoint page accessible to all and settings custom themes based on User Pin
ihoecken12-Nov-12 1:17
memberihoecken12-Nov-12 1:17 
GeneralRe: How to make a sharepoint page accessible to all and settings custom themes based on User Pin
balaji101012-Nov-12 1:41
memberbalaji101012-Nov-12 1:41 
Question[SOLVED] Unable to add webpart to page from script, but successfull from command line using same code [modified] Pin
_HawkeyeD5-Nov-12 10:41
member_HawkeyeD5-Nov-12 10: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 3:05
memberihoecken6-Nov-12 3:05 
GeneralRe: Unable to add webpart to page from script, but successfull from command line using same code Pin
_HawkeyeD6-Nov-12 5:04
member_HawkeyeD6-Nov-12 5:04 
AnswerRe: Unable to add webpart to page from script, but successfull from command line using same code Pin
_HawkeyeD9-Nov-12 7:30
member_HawkeyeD9-Nov-12 7:30 
QuestionAdding users to the default members group Pin
Aptiva Dave1-Nov-12 9:17
memberAptiva Dave1-Nov-12 9:17 
AnswerRe: Adding users to the default members group Pin
ihoecken4-Nov-12 21:54
memberihoecken4-Nov-12 21:54 
GeneralRe: Adding users to the default members group Pin
balaji10108-Nov-12 1:12
memberbalaji10108-Nov-12 1:12 
AnswerRe: Adding users to the default members group [modified] Pin
ihoecken8-Nov-12 1:21
memberihoecken8-Nov-12 1:21 
GeneralRe: Adding users to the default members group Pin
balaji10108-Nov-12 1:33
memberbalaji10108-Nov-12 1:33 
AnswerRe: Adding users to the default members group Pin
ihoecken8-Nov-12 1:36
memberihoecken8-Nov-12 1:36 
QuestionSharePoint Standard 2007 to SharePoint 2007 Enterprise Pin
fmorales0931-Oct-12 11:24
memberfmorales0931-Oct-12 11:24 
AnswerRe: SharePoint Standard 2007 to SharePoint 2007 Enterprise Pin
ihoecken4-Nov-12 21:48
memberihoecken4-Nov-12 21:48 
QuestionNot been able to log into SharePoint site after deploying new WSP Pin
NetMan201229-Oct-12 23:21
memberNetMan201229-Oct-12 23:21 
AnswerRe: Not been able to log into SharePoint site after deploying new WSP Pin
ihoecken30-Oct-12 0:06
memberihoecken30-Oct-12 0:06 
AnswerRe: Not been able to log into SharePoint site after deploying new WSP Pin
arunkumaryoyo31-Oct-12 20:52
memberarunkumaryoyo31-Oct-12 20:52 
Questionshare document can detete by only who can uploaded not to others Pin
HemadriT26-Oct-12 6:19
memberHemadriT26-Oct-12 6:19 
AnswerRe: share document can detete by only who can uploaded not to others Pin
ihoecken28-Oct-12 23:35
memberihoecken28-Oct-12 23:35 
GeneralRe: share document can detete by only who can uploaded not to others Pin
HemadriT1-Nov-12 5:53
memberHemadriT1-Nov-12 5:53 
AnswerRe: share document can detete by only who can uploaded not to others Pin
ihoecken4-Nov-12 22:01
memberihoecken4-Nov-12 22:01 
QuestionHow to host sharepoint site in IIS Pin
HemadriT26-Oct-12 5:22
memberHemadriT26-Oct-12 5:22 
AnswerRe: How to host sharepoint site in IIS Pin
ihoecken28-Oct-12 23:38
memberihoecken28-Oct-12 23:38 
QuestionPickerEnity question Pin
Aptiva Dave23-Oct-12 9:44
memberAptiva Dave23-Oct-12 9:44 
AnswerRe: PickerEnity question Pin
Aptiva Dave23-Oct-12 10:45
memberAptiva Dave23-Oct-12 10:45 
GeneralRe: PickerEnity question Pin
balaji10108-Nov-12 1:14
memberbalaji10108-Nov-12 1:14 
QuestionOn-page Anchor Points [solved] [modified] Pin
JimmyRopes21-Oct-12 4:18
memberJimmyRopes21-Oct-12 4:18 
AnswerRe: On-page Anchor Points Pin
ihoecken21-Oct-12 23:15
memberihoecken21-Oct-12 23:15 
GeneralRe: On-page Anchor Points Pin
JimmyRopes22-Oct-12 12:42
memberJimmyRopes22-Oct-12 12:42 
QuestionSharePoint Migration steps Pin
chakravarthy3517-Oct-12 20:49
memberchakravarthy3517-Oct-12 20:49 
AnswerRe: SharePoint Migration steps Pin
ihoecken17-Oct-12 23:01
memberihoecken17-Oct-12 23:01 
QuestionHow to deploye sharepoint site Pin
HemadriT17-Oct-12 4:41
memberHemadriT17-Oct-12 4:41 
AnswerRe: How to deploye sharepoint site Pin
ihoecken17-Oct-12 6:03
memberihoecken17-Oct-12 6:03 
GeneralRe: How to deploye sharepoint site Pin
HemadriT17-Oct-12 6:28
memberHemadriT17-Oct-12 6:28 
AnswerRe: How to deploye sharepoint site Pin
ihoecken18-Oct-12 5:12
memberihoecken18-Oct-12 5:12 
Generalcolumn permission Pin
johnson_shalom16-Oct-12 21:43
memberjohnson_shalom16-Oct-12 21:43 
AnswerRe: column permission Pin
ihoecken16-Oct-12 22:20
memberihoecken16-Oct-12 22:20 
GeneralRe: column permission Pin
johnson_shalom18-Oct-12 22:06
memberjohnson_shalom18-Oct-12 22:06 
AnswerRe: column permission Pin
ihoecken21-Oct-12 23:08
memberihoecken21-Oct-12 23:08 

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
Web01 | 2.8.150520.1 | Last Updated 14 May 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid