Författararkiv: Johannes Milling

Generate Guid easily with ReSharper

Sometimes the smallest things make our life a lot easier.

Like this tiny – but great – feature from ReSharper for generating Guids. Simply write nguid in any file, no matter the type, and press tab.


ReSharper will then generate a new Guid for you, and even let you choose a format.


Just one of those small, nice things making ReSharper a delight to work with. =)

(Thanks for the tip Villy)

Embedding a PDF file dynamically on a web page

So embedding a PDF to a web page is pretty easy. All you need to do is to add an object or embed element to your HTML.

Actually, you could use only object or embed, depending on browser support. But using both is a safeguard. If object fails to load it’s data, it will render it’s child elements instead, in this case the embed element.

There are spaces between the < and object/embed elements since WordPress doesn’t allow these elements. Remove it if copying this code.

But what if you don’t know what PDF file you want to display, and you want to load it dynamically? This is what I was trying to do, and of course I ran into problems displaying the PDF in Internet Explorer. This is how you should be able to set which file will be loaded using javascript. First, we add the elements to our HTML. To make it easier to get the elements in our javascript, give them a unique id.

Then, in javascript, we SHOULD be able to change witch PDF should be shown like this.

It works perfectly in Chrome, but in IE (tried versions 10 and 11 as well as emulated 8 and 9), you will only see a grey frame with nothing in it. When debugging the javascript the attribute is actually updated, and everything seems to be fine, except you can’t see the PDF. Very frustrating. After a bit of googling i found a solution here (it’s not the marked answer). Instead of using <element>.setAttribute(), which should work, you need to modify the outerHTML attribute of the element.

However, this will only work if you already have the attribute present. So either you need to have a default url in your HTML, or you need to set the attribute first, which both is kind of annoying. Putting it all together it might look something like this.

And there you go. Dynamically loading an embedded PDF to a web page, working in IE 8-11 and Chrome, and hopefully other browsers as well.

My main sources/further reading:

Export SharePoint list data to XML directly from the GUI

The other day I learned of a cool function in SharePoint which can come in handy if you want to export a list to XML. And best of all, no code, script or SharePoint Destroyer… *cough* … Designer needed.

What you do is simply to call an OOTB SharePoint service and specify in the query string what it is you want, and in which format:

So what you do is to call the owssvr.dll from the site you want to export from, and in the query string add Cmd=Display. Then you add the List and View you want to export from. If you want all items and fields you simply set Query=*. Mind, you still might have to reference a view, even though it won’t be used when using the query. And in the end, add XMLDATA=TRUE. That’s it!

An example of how it might look:

You can get the guid to the list by simply going to the list settings and copy the guid from the url. Its the guid after “…&List=”.

That’s it. =)

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.