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?
list = web.Lists.TryGetList("Documents"); // obvious "if"s
contentType = list.ContentTypes["CT1"];
field = contentType.Fields.GetFieldByInternalName("DocumentType") as
= some guid
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.
list = web.Lists.TryGetList("Documents");
field = list.Fields.GetFieldByInternalName("DocumentType")
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.
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...
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.
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.
Adding ribbon buttons can be a frustrating process. I show how to do it the fast way during development, for easier troubleshooting.
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.
This post explains how you can run a (SharePoint) Powershell command from C#/SharePoint.
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
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.
The clock I made in part i displays the time in "long" - "It's a quarter to ten" (but in Norwegian).
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".
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.
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.
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.