Kategoriarkiv: SPField

Unhide a hidden SPField using PowerShell

Another task that’s much harder than it should be. Setting the hidden property of a SPField to false.

First you get the field itself. In this example we change the setting of the field in the library, but it could just as well be done on the site level.

Then, when you have the actual field, you just need a bit of reflection magic.

I don’t know why, but simply setting field.Hidden = $false doesn’t work. But the code above does!

Solution comes from here.

Get and format DateTime string from SharePoint DateTime field

A collegue of mine (his blog here) showed me something nice yesterday. We have a webpart which shows how long ago some list items where created by simply getting the DateTime string from the standard “Created” column.

string x = ((DateTime)item[SPBuiltInFieldId.Created]).ToString();

We ran into trouble however, when we used this webpart on a server in a country using a different time format. The problem was easily fixed like so:

string x = ((DateTime)item[SPBuiltInFieldId.Created]).ToString(“s”);

This converts the DateTime string to a standard format which allows it to be understood by various javascript and jQuery functions and plugins, which was exactly what we needed.

Here is a list of other formats you can get with this method by simply replacing the “s” with another letter.