Blog Stats
  • Posts - 24
  • Articles - 0
  • Comments - 16
  • Trackbacks - 0

 

Thursday, May 30, 2013

"This functionality is unavailable for fields not associated with a list"


I wanted to set the default termset node of a taxonomy field in a content type in a list.

(…the field should have different defaults depending on the type of library, but that's not important right now)

 

So. Easy. Get the list, get the content type, get the field, set the default. What could be easier?


var list = web.Lists.TryGetList("Documents"); // obvious "if"s removed

var contentType = list.ContentTypes["CT1"];

var field = contentType.Fields.GetFieldByInternalName("DocumentType") as TaxonomyField;

field.SspId = some guid

field.etc

field.Update(); // KABLAM

 

And that's when you receive the unfortunate error that is the subject of this tiny post.

Let us skip all the wrong attempts I made at solving this, and og straight to the solution: Do not get the field from the content type - get it directly from the list instead.


var list = web.Lists.TryGetList("Documents");

var field = list.Fields.GetFieldByInternalName("DocumentType") as TaxonomyField;


It does make sense. You can only change the field on a per list (or globally) scope; you can not do it per content type.

Sunday, February 10, 2013

Minimal SharePoint 2013 development environment


What kind of hardware do you need to do SharePoint environment?
Microsoft recommends a minimum of 32Gb for SharePoint Server, less for SharePoint Foundation.
But there are not many laptops in the wild with 32Gb; certainly none that I'd like to have in my lap. (My Dell 4600 does have 32Gb, but I'm a wee fellow at 1.87m, and rather too many kilos.)
This is written on a Samsung 900somethingsomething, a beautiful ultrabook with 8Gb of ram and a 256 SSD.
Probably the nicest thing about this machine is what Apple-users have taken for granted for years now; instant on.
I open the lid, and I can start typing almost immediately (I've disabled "require password when resuming).

So, given that this is the PC I like to use when I'm pretending to watch "When Harry met Sally" or "Eurovision Song Contest," wouldn't it be nice if this machine can run SharePoint?
Purchase Win8Pro, enable hyper-v, and...
Joy!
I chose to install SP with the minimum of services. No search, workflow, excel services or similar for me. If I want to play with those things, I'll do it at work.
I gave the vm 5550Mb, which win8 claimed was the maximum.
With VS2012 and IE with a couple of sites open, I'm still juuust south of 4Gb.
Which isn't bad.
I've also configured my Samsung for silent running (i.e. max battery lifetime, and slow down the cpu so that the fan doesn't need to spin). So it isn't fast. But the things I want to play with, team sites, apps, ecm, do work.

Wednesday, February 6, 2013

Use "Add as link" to unit test SharePoint


Unit testing SharePoint is difficult for a number of reasons.

One of the better known ones is perhaps that of the GAC; the .net loader ("Fusion") will use assemblies from the GAC even if you specify the full path to the newly-built-but-not-yet-tested-dll.

If you are unaware of this, it can be an extremely frustrating experience - or so I've been told... ("...but... how can that code possibly still be wrong?! I've commented it all out!")

In the past I've attempted daft things like renaming the dll to "something that has never been gacced" (ie. <whatever>2.dll), and adding that dll as a reference in my test project. (in case you want to know: No, it doesn't work)

Today I came across a better way in a presentation by Bill Ayers. And by better, I mean it actually works.

Briefly: In the test project, "add as a link" the class you want to test. ("Add existing item...", browse to the cs file in the SharePoint project, select it, and add as link - it's a drop-down button.)

Of course, the linked cs-file is now (also) a part of the test-project, so if the file makes calls to code in other files, they have to be linked to, too. Etc.


Tuesday, January 29, 2013

Edit multiple items as ribbon button


Adding ribbon buttons can be a frustrating process. I show how to do it the fast way during development, for easier troubleshooting.

Tuesday, November 20, 2012

Finding the error from a correlation ID


We create an application which searches the SharePoint log for events matching correlation guids it finds on the clipboard. I.e. copy the correlation ID SharePoint gives you, switch to this application, and enjoy.

Wednesday, September 19, 2012

Running Powershell from within SharePoint


This post explains how you can run a (SharePoint) Powershell command from C#/SharePoint.

Saturday, July 21, 2012

Installing SharePoint 2013 preview on a standalone, workgroup server


If you try to install SP2013 on a standalone (i.e. not joined to a domain controller), you will eventually get an error.

"Service running under Network Service account in workgroup environment is not supported."

To avoid this error, create the configuration database after the main setup before you run the “Configuring SharePoint Products” wizard.

Open Powershell, add the usual snapin if necessary (depends on what you do when I say “Open Powershell”!), ignore the warning about missing implementingType for education.institution.dll, and then do a

New-SPConfigurationDatabase

That’s it! Now you can run the Config wizard, and everything should be ok. Well, things were ok on the three servers I’ve tried it on so far. 

Note: Do not do this if you ever intend to do any workflow stuff. Things will not work.

Thursday, July 5, 2012

Html 5 clock, part ii - CSS marker classes and getElementsByClassName


The clock I made in part i displays the time in "long" - "It's a quarter to ten" (but in Norwegian).

QuarterToTen

To save space, some letters are shared, "sevenineight" is four letters shorter than "seven nine eight".

We only want to highlight the "correct" parts of this, for example "sevenineight".

When I started programming the clock, each letter had its own unique ID, and my script would "get" each element individually, and highlight / hide each element according to some obscure logic.

I quickly realized, despite being in a post surgery haze, …this is a stupid way to do it.

And, to paraphrase NPH, if you find yourself doing something stupid, stop, and be awesome instead.

We want an easy way to get all the items we want to highlight.

Perhaps we can use the new getElementsByClassName function?

Try to mark each element with a classname or two.

So in "sevenineight": 's' is marked as 'h7', and the first 'n' is marked with both 'h7' and 'h9' (h for hour).

<div class='h7 h9'>N</div><div class='h9'>I</div>

getElementsByClassName('h9') will return the four letters of "nine".

Notice that these classes are not backed by any CSS, they only appear directly in html (and are used in javascript).

I have not seen classes used this way elsewhere, and have chosen to call them "marker classes" - similar to marker interfaces - until somebody comes up with a better name.

Wednesday, July 4, 2012

Html 5 – new size units


There are some new size units with CSS 3, which allows you to resize elements relative to the viewport size. They are vw, vh, vmin (that’s vm in IE), and perhaps vmax. (Viewport width, height, smaller of the two, larger of the two.)

8vw is 8% of the viewport width – or 205 pixels on my 2560 screen.

I created a tiny demo clock which sizes the elements so that it uses the whole screen.

Clock – in Norwegian, but it’s the source that is interesting…

Bug: Resize does not work.

Tested for IE 9 & 10 and Chrome. Firefox and Safari: does not work.

Saturday, June 30, 2012

Creating large SharePoint structures from Powershell and xml, part ii


In this second part, we show how we can build an xml structure from information we get from SharePoint. This xml can later be edited, and used as input to the SharePoint creator from part i.
 

 

Copyright © Norgean