wo 11 april 2012 14:22
Got this error after creating some taxonomy fields and then importing them into Visual Studio using CKSDev. If I then tried to connect a term to the taxonomy field the error occured.
(“The object has been updated by another user since it was last fetched”)
This did not happen at first, but only after removing my Development Site Collection, and then deploying again from Visual Studio to a new clean sitecollection.
The error was thrown because there was a version number specified in the field xml of the taxonomy field. More detailed information can be found at: http://www.mpspartners.com/2012/02/SharePointTaxonomyFieldandTheobjecthasbeenupdatedbyanotherusersinceitwaslastfetched/
vr 11 november 2011 01:45
changed to
because first statement would fail if checked-out by someone else.
This post will descibe what you need, and what to watch out for when you are planning to add webparts to a publishing page using powershell. Scroll down and skip the plumbing part for the good bits.First of all: get PowerGUI (or PowerGui for visual studio using the extension gallery) this will make your life a whole lot easier.Lets start with the information we have and create a batchfile. This is not required, but makes life a lot easier when you want to execute your powershell script multiple times, or have to deal with a Sys-Op that does not know any powershell.
echo off SET URL="http://contoso.com" SET WEBPARTTOADD="Related Documents" SET ZONEID="Zone1" powershell.exe -command .\AddWebParts.ps1 '%URL%' '%WEBPARTTOADD%' '%ZONEID%' pause
Param($siteUrl,$WebPartsToAdd,$ZoneId);
$AllowedPageLayouts = "ArticleLeft.aspx","ArticleLeft.aspx";
Add-PSSnapin Microsoft.SharePoint.PowerShell
function InsertWebPartInWebPartZone($siteUrl, $WebPartsToAdd, $webPartZone) { # Create a new instance of the site. $site = Get-SPSite (New-Object System.Uri($siteUrl)); # Iterate trough all the pages foreach($web in $site.AllWebs) { Write-Host "===============================" Write-Host "Currently parsing" $web.Title; Write-Host "===============================" #check if we are in a publising web if( ! [Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($web) ) { Write-Host "Web is not a publishing web, skipping" continue; } # Retrieve the pages library $pagesLibrary = $web.Lists["Pages"]; $allowunsafeupdates = $web.AllowUnsafeUpdates $web.AllowUnsafeUpdates = $true # Iterate through all pages foreach($page in $pagesLibrary.Items) { #check for null if($page -eq $null) { continue; } #check if page is checked out already #if ($page.File.Level -eq [Microsoft.SharePoint.SPFileLevel]::Checkout) if ($page.File.CheckOutType.value__ -ne 2) #2 = SPCheckOutType.None { Write-Host $page.Url "is Checked-Out already. Skipping } else { #check if page is a publising page and if it is of allowed pagelayouts to change $pubPage = [Microsoft.SharePoint.Publishing.PublishingPage]::GetPublishingPage($page) if( ($pubpage -ne $null) -and ($AllowedPageLayouts -contains $pubPage.Layout.Name)) { Write-Host "Page is of valid layout, processing page (" $page.Name ")" } else { Write-Host "Page is of invalid layout (" $pubPage.Layout.Name "). Skipping." continue; } Write-Host "starting page processing -----" # Checking out page $page.File.CheckOut() $index = 0; foreach($webPartToAdd in $WebPartsToAdd) { # Retrieve the webpart from the webpartgallery $webPart = GetWebPartFromGallery $site $webPartToAdd; if($webpart -eq $null) { Write-Host "Unable to retrieve $webPartToAdd to insert. Skipping."; continue; } # Check if the page already contains this webpart, if so, remove it RemoveWebPartFromPage $page $webPart.Title; # Add or re-add the webpart to the page in the specified zone AddWebPartToPage $page $webPart $webPartZone $index; # Update the index $index++; } # Build up the message $checkInMessage = "This page is checked in by the Add WebPart Script"; # Check the page in and Publish if required $page.File.CheckIn($checkInMessage); if($page.ParentList.EnableMinorVersions -eq $true) { $Page.File.Publish("Published"); } Write-Host "page done" } } $web.AllowUnsafeUpdates = $allowunsafeupdates; # Dispose of the web $web.Dispose(); } }
Get WebPartFromGallery reads a webparts XML definition. It reads the definition from the webpartgallery and finds the webpart based on the webpart name.
function GetWebPartFromGallery($site, $webPartName) { Write-Host "Getting " $webPartName " from gallery." # Get the rootweb (and get the webpart gallery) $web = $site.OpenWeb(); $webPartGallery = $web.Lists["Web Part Gallery"] if($webPartGallery -eq $null) { Write-Host("Unable to retrieve Webpartgallery"); } $webpart = $null; foreach($wp in $webPartGallery.Items) { #find the webpart we are looking for if($wp.Title -eq $webPartName) { $webpart = $wp; Write-Host "Webpart found in gallery" break; } } if($webpart -eq $null) { Write-Host("Unable to retrieve webpart: $webPartName"); } return $webpart; }
#Remove webpart based on Webpart title function RemoveWebPartFromPage($page, $webPartTitle) { #make sure the page is checked-out if ($page.File.Level -ne [Microsoft.SharePoint.SPFileLevel]::Checkout) { Write-Host $page.Url " is not Checked-Out. Cannot remove webpart from the page."; return $false; } # set the current httpcontext, needed for contentquerywebparts webparts that use the # xslitemlink, xslmainlink or xslheaderlink property # else makeserverrelative url will fail, because there no context if ($null -eq [System.Web.HttpContext]::Current) { $sw = New-Object System.IO.StringWriter $resp = New-Object System.Web.HttpResponse $sw $req = New-Object System.Web.HttpRequest "", $web.Url, "" $htc = New-Object System.Web.HttpContext $req, $resp #explicitly cast $web to spweb object else sharepoint will #see it as a PSObject, and AddWebpart wil fail $htc.Items["HttpHandlerSPWeb"] = $web -as [Microsoft.SharePoint.SPweb] [System.Web.HttpContext]::Current = $htc } $webPartCollection = $page.Web.GetWebPartCollection($page.Url,[Microsoft.SharePoint.WebPartPages.Storage]::Shared); $webPartStorageKey = $null; foreach($wp in $webPartCollection) { $webpart = $wp -as [Microsoft.SharePoint.WebPartPages.WebPart]; if($webpart.Title -eq $webPartTitle) { $webPartStorageKey = $webpart.StorageKey; break; } } if($webPartStorageKey -eq $null) { return $false; } $webPartCollection.Delete($webPartStorageKey); return $true; }
# Adds the desired webpart to the page function AddWebPartToPage($page, $webPartListItem, $webpartZoneId, $index) { Write-Host "Adding" $webPartListItem.Name " to " $page.Name; if ($page.File.Level -ne [Microsoft.SharePoint.SPFileLevel]::Checkout) { Write-Host $page.Url "is not Checked-Out. Cannot add webpart to the page."; return $false; } # Get the webpartmanager $wpManager = $page.Web.GetLimitedWebPartManager($page.Url,[System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared); # Get the webpart's xml $errorMsg = ""; $xmlReader = New-Object System.Xml.XmlTextReader($webPartListItem.File.OpenBinaryStream()); $webPart = $wpManager.ImportWebPart($xmlReader, [ref]$errorMsg) -as [Microsoft.SharePoint.WebPartPages.WebPart]; try { # set the current httpcontext, needed for contentquerywebparts webparts that use the # xslitemlink, xslmainlink or xslheaderlink property # else makeserverrelative url will fail, because there no context if ($null -eq [System.Web.HttpContext]::Current) { $sw = New-Object System.IO.StringWriter $resp = New-Object System.Web.HttpResponse $sw $req = New-Object System.Web.HttpRequest "", $web.Url, "" $htc = New-Object System.Web.HttpContext $req, $resp #explicitly cast $web to spweb object else sharepoint will #see it as a PSObject, and AddWebpart wil fail $htc.Items["HttpHandlerSPWeb"] = $web -as [Microsoft.SharePoint.SPweb] [System.Web.HttpContext]::Current = $htc } # Add webpart to the page $wpManager.AddWebPart($webPart, $webpartZoneId, $index); } catch { Write-Host "An error occurred. Unable to add webpart " $webPartListItem.Title; Write-Host $_.Exception.ToString(); } [System.Web.HttpContext]::Current = $null $wpManager.Dispose(); return $true; }
Start-Transcript InsertWebPartInWebPartZone $siteUrl $WebPartsToAdd $ZoneId Stop-Transcript
wo 5 oktober 2011 11:46
<A onclick="GoToLink(this);return false;" href="http://www.derde.net/feedback/_layouts/listform.aspx?PageType=8&ListId={B0EF9608-FC48-401E-9343-4EDDF4585131}&RootFolder=">new feedback</A>
vr 30 september 2011 17:56
Found out today that the behaviour of the PublishingWebControls:EditModePanel changed between MOSS2007 and SP2010.
Apparently,now in SP2010, you need the EditItem Permission to be able to see what is in an EditModePanel even if the PageDisplayMode attribute is set to "Display".
So basically it works like a SPSecurityTrimmedControl
Example:
<SharePoint:SPSecurityTrimmedControl PermissionsString="EditListItems" runat="server"> </SharePoint:SPSecurityTrimmedControl>
Update This behaviour has been changed back to 2007 behaviour as of SP1 for Sharepoint 2010
di 27 september 2011 11:36
I keep losing this really handy xsl for displaying the raw search result XML in SharePoint. Blogging it for future reference :).
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="/"> <xmp><xsl:copy-of select="*"/></xmp> </xsl:template> </xsl:stylesheet>
di 13 september 2011 15:32
di 13 september 2011 11:46
[Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges( { $site = get-spsite "http://localhost/nonfarmadminsitecollection" } ) $elevatedSite = new-object Microsoft.SharePoint.SPSite([Guid]$site.ID,$site.SystemAccount.UserToken)
vr 22 juli 2011 17:09
Today I waisted some time installing Windows 7 on my new Lenovo W510.
It has 2 HDD's so I could not use a win7 DVD. No problem there.Borrowed a USB stick from a collegue (Thnx Jan) and downloaded this little tool. This allows you to copy an ISO of Windows7 to a USB drive and install it from there.
After copying the windows7 files to the USB drive I was ready to get started. So I put the drive in the side USB ports of the W510 and gor started. 30 minutes and lots of error messages later I decided to BING it.
It turns out you cannot install the laptop with a external USB drive (or USB dvd player) on any but the rear usb.I guess that this port is on another controller that is supported by default and the side (USB 3.0) ports are on another controller that is not.
Just thought I would put it out there for everyone else
ma 18 juli 2011 11:38
The issue occurs on a publishing site that has a contenttype containing a Publishing Hyperlink (SPFieldLink).Inserting a link with the Link Tools Tab of the ribbon works fine, but removing the link after it has been set does not. Found a post on Stackoverflow that describes the issue in detail:For quick reproduction: (steps and testing by M. Siepel)
I did some testing on it and these are the results:
A little more time on the Bing machine resulted in finding a post from M Siepel on the Microsoft forums:http://social.msdn.microsoft.com/Forums/en-AU/sharepoint2010general/thread/8ce468ec-096b-4ad2-a1e9-0bfb93cecf95
Basicly it states that the bug can be reproduced consistently and it has been reported to the product team. Lets hope this will be fixed in the next CU.
Someone already created a powershell fix, but that is not really end-user friendly. I will update this post
Param([string]$site0=http://mysharepoint, [string]$list0="My List", [string]$itemKey0="Item Key", [string]$linkUrl0=http://newlink, [string]$desc0="New description", [string]$toolTip0="New Tooltip") $site = Get-SPSite($site0) $rootWeb = $site.rootWeb $lists = $rootWeb.Lists $list = $lists[$list0] $items = $list.Items $listItem = $items | Where-Object {$_.Name -eq $itemKey0} $linkUrl = $listItem["Link Url"] $linkUrl.NavigateUrl = $linkUrl0 $linkUrl.Description = $desc0 $linkUrl.ToolTip = $toolTip0 # this is the trick - set the object back to listItem $listItem["Link Url"] = $linkUrl $listItem.Update()
ma 6 juni 2011 14:28
About a week ago Microsoft published the XML Schema Definition (XSD) files for the Microsoft Visio 2010 XML Drawing (.vdx) format. This schema is also known as DatadiagramML. This should make it alot easier to use the visio file to generate code based in the visio file.
The DatadiagramML Schema for Visio 2010 consists of three .XSD files:
More information about the schema is available in the Visio 2010 XML Schema Reference on MSDN.