Skip to main content

Posts

Showing posts from 2011

Copy lookup fields in SharePoint 2010

I had a scenario where I had to copy items to different sites in the same site collection. I got problems when I tried to copy an item with a lookup field. It copies ok but the lookup was all wrong since they pointed to the item with the same id as the source witch was not always the same item in the look up list. Then I got the idea of querying the look up list at the target site to see if it had a field with the same value as the source site. Using this I made the lookup field point to that field in the item and now it was able to point to the right item. SPFieldLookup lookupField = (SPFieldLookup)field; string lookUpListName = contextWeb.Lists[new Guid(lookupField.LookupList)].Title; string lookUpFieldName = lookupField.LookupField; // Get the target list on the copy to web. SPList copyToListLookUp = copyToList.ParentWeb.Lists[lookUpListName]; SPField lookUpTargetF...

Deploying Custome XSLT in views

Sometimes it is nice to know how to use SharePoint Designer to create SharePoint elements. One such scenario is use of xslt to change style depending on a variable in a list example; set s color on the prices that are more than an amount on a list. One thing is doing it in SharePoint designer on your local developer computer another is to translate that to a solution you can deploy. In this example I’m using SharePoint designer to set a rule that says that if a price on an order list is higher than 600 the background color to be set to Red. First I created the scenario in SharePoint Designer: First create an Orders list as a Custom list and add a Column called price, make sure to have one test item. Then open the list in SharePoint Designer. Here you can create the xslt by clicking on the All Items, then select a row in design view and select Conditional Formation. Do the formation that you need and save. In code view look for the XSL tag and make a copy of the content of the xsl tagl....

Simple SharePoint 2010 Ribbon example

As we all know SharePoint 2010 came with the new ribbon interface. I have not had much time exploring how to add elements to the ribbon, so I decided to have a go at it. I decided to use a blank site and try to add a ribbon to the main web part page. With god help from the Professional SharePoint 2010 Development book, here is how i did it. I started by creating two projects in my solution, one to deploy the images and one to deploy the ribbon feature. The reason for this is that I like to use the sandbox solutions as much as possible. As the images are going into the _layouts\images catalog and therefor needs to be a Farm solution and the ribbon with only one feature can be a sandbox solution. The way the Ribbons are organized are by a path. In my example the path is “Ribbon.WebPartPage.Edit.Controls._children” , here I'm saying that I want my ribbon to be on WebPart pages under the edits controls, _children means that I want it as new child not override an existing one. I found t...