Wednesday, September 26, 2012

Upload content type template through PowerShell

In my current project, we make use of numerous different Word templates. To make template a part of the automated build process, I made a PowerShell script that

  1. Loop through a folder on the disk
  2. Find subfolder, named in a given way
  3. Find the template
  4. Finds the content type in SharePoint
  5. Upload the template to the content type resource folder
  6. Save the content type

And the content type is ready to get published.

PowerShell script:

1 Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction:SilentlyContinue | Out-Null
2 $url = "http://win-l2sfc3oetnn/sites/doctemp/" #ContentTypeHub Url
3 $templateFolderPath = "C:\Projects\demos\TemplateDemo"
4 $filter = "*.dotx", "*.potx", "*.vst", "*.xltx"
6 $contentTypeFolders = ls $templateFolderPath | where {$_.PsIsContainer}
7 $templateCount = (ls $templateFolderPath -Include $filter -Recurse | where {!$_.PsIsContainer}).Count
8 $i = 1
9 $fileMode = [System.IO.FileMode]::Open
11 $contentTypeFolders | % {
12 $path = $_.FullName
13 $foldername = $_.Name
14 $ctindex = $foldername.LastIndexOf("0x")
16 if($ctindex -gt 0) {
18 $contenttypeid = $foldername.Substring($ctindex, $foldername.Length - $ctindex)
19 $spcontenttypeid = New-Object Microsoft.SharePoint.SPContentTypeId $contenttypeid
21 ls -Path $path | % {
22 #Need to open a new spweb object, to "refresh" the current content type object, to aviod database update conflict
23 $web = Get-SPWeb $url
24 $spcontenttype = $web.ContentTypes[$spcontenttypeid]
25 $fileFullname = $_.FullName
26 $filename = $_.Name
28 Write-Progress -PercentComplete (($i / $templateCount) * 100) -Activity "Uploading templates" -Status "$filename on content type $($spcontenttype.Name)"
30 $i++
31 try{
32 #open the document template, as a filestream
33 $fileStream = New-Object "System.IO.FileStream" -ArgumentList $fileFullname, $fileMode
34 #add the file (SPFile) to the content type resource folder
35 $spcontenttype.ResourceFolder.Files.Add($filename, $fileStream, $true) | Out-Null
36 $fileStream.Close()
37 #set the current document template file to be the document tmeplate
38 $spcontenttype.DocumentTemplate = $filename
39 #update the content type
40 $spcontenttype.Update($true)
41 }
42 finally{
43 $fileStream.Close()
44 }
45 }
46 }
47 }

Download link

Wednesday, September 19, 2012

QuickPart values ​​do not update with a blank Word templates

In my current project, we make use of numerous different Word templates, but the basic for them all is they have a header and footer and they are the same. Header and footer containing quick-party showing SharePoint metadata, for e.g. status of the document. Of cause the values must be updated if the user changes them either from Word (document information panel) or from the SharePoint UI. We made a lot of templates, from meeting minutes to a letter template and all the values ​​from the quick-party fields updated fine but our most simple Word template that only contain, header and footer, did not work. After a very long search we came to the Word template must include a text and a space is enough.

This will not work:1

This will work:2

Wednesday, September 12, 2012

Custom document infomartion panel, InfoPath form as letter selector

I got a request from a customer, where they needed to add a custom address field to the head in a Word template. The address list need to come from a single source and easy to by update.

The tasks look like this:

  1. Create the custom address list in SharePoint. Need a multiline field, where the address with line breaks can be added.
  2. Content type with a Word template and custom information panel “InfoPath form”
  3. The InfoPath form
  4. Configure the document library
  5. The Word template
  6. Upload the Word template
  7. Test

Creating the list for the address

Create a custom list.


Adding the multiline field.


Add value to the list.


Creating the content type

I call my content type “Letter”.


Add multiline text field, to the content type. In my demo i use the build in field Address.


When done, the content type look like this. Click on the document infomartion panel settings link.


Clikc on the "Create a new custom template” link.


InfoPath view

When InfoPath is finish loading, click on the “show field” button in the ribbon, “manage data connection” and then “Add…”.


Datasource wizzard

Follow the data connection wizzard.



The locatition is the url to the SharePoint site where the custom address list is created.






The done, the new data connection is add to the data connection lists.


Change the control

Right click on the Address field textbox, select “Change Control” and select “Drop-Down List Box”.


Change the control properties

Click on the Address field and select Drop-Down List Box Properties.


Change the properties to look like this.


Change the design a bit

Remove the line break after the first horizontal region.


Publish my form

Click on the Quick Publish button, in the right top corner.


InfoPath will akes if you want to save the InfoPath template, before publish it.


Configure and  add content type to document library

On the document library, go to the document library settings page and under the “Advanced settings” page, change the setting “Allow management of content types” to true.


And the “Letter” content type.


Create the Word template

Go back to the document library and create a document based on the content type. This is the easyed way to create a template with the proper field add to the Word template.


Then Word is finish loading, go to the backstage, by clicking on the “file” icon, then click on the “properties” and select “Show Document Panel”.


Go back to Word.

In my demo, i edit the header. Go the Ribbon, under the “Insert” tab, select “Quick Part”, “Document Property” and then the “Address” field.


My template ends up looking like this.


Save the document as a “dotx” file (Word template file).


Upload the template

Find the “Letter” content type, select the “Advanced settings”.


Upload the template og click on the “OK” button.


The test

Go back to the document libary, click on the “Letter” content type in the “new document” button in the Ribbon.


Select the address in the document infomation panel.


And we are done Smiley

Wednesday, September 5, 2012

A great migration tool

On my current project, we needed that to merger quite a lot of documents from one SharePoint to another SharePoint. To begin with, we expected that the project should do the merger of the documents and therefore we should spend a lot of time on it. We discuss it in the project group and came up with some solution proposal, which ranged from console application to PowerShell. However, we kept coming back to a problem. That we in the project did not know the structure that we had to migrate documents into, that was only our customer who is familiar structure. Of course, we could talk to the customer about how we should save every single document. After some discussion back and forth, we end up finally but not a particularly good solution. So back to the drawing board. Now, if we could create a program that could even be able to use and even stand to migrate documents, it would be the best solution. After some discussion back and forth, we end up finally, not a particularly good solution. So back to the drawing board. Now, if we could make a program that the customer could use and themselves migrate the documents, it would be the best solution. We estimate tasks and found out, if we create the program, it would take a very long time to develop. Therefore, we began to search for a 3-party tool. We found a few tools, but we found a tool from Share Gate.

ShareGate tool had several advantages, which we need, as they highlight on their website:

  • Drag & drop
  • Migrate SharePoint list items and documents
  • Preserve version history
  • Preserve created and modified information
  • Assign new content types
  • Field validation

But the most important of all, an interface that is easy and inviting, so that our customer does not need constant support to them and it's ShareGates "Copy SharePoint Content" tool.

Product Information:

Monday, August 27, 2012

SharePoint Manager 2013 release note

I release the SharePoint Manager 2013 some time ago, more precisely on Jul 19 2012 and it now has over 2500 downloads on CodePlex witch I think is very good. This version is only intend as an upgrade of the 2010 version. However, I has added two new features. Both based on the feedback that has come from the 2010 version about speed. The first function is the most visual of the two. Function is plain and simply a splash screen that displays a picture as soon as you start the SharePoint Manager. The second feature is a configuration value in app.config file. The function is called “ShallowExpand”. Set it to true and the next time you start the SharePoint Manager only loads the farm and webapplication objects into treeview.

Screenshot of the loading screen:

Screenshot then the shallowexpand is false:

Screenshot then the shallowexpand is true:

But what should you expect? Keutmann and I are working to rewrite the whole core, so we would like to do SharPoint Manager yet quick and support even more properties

Saturday, January 21, 2012

To use one-liner or not to use one-liner?

A recurring problem in many of the projects I'm working on is a link to open a link up in a pop / model window. My first thought was to do as Venkatesh R've described it here By making a new SP.UI. $ create_DialogOptions (); object and call SP.UI.ModalDialog.showModalDialog. Not because it's hard but if you do not need the callback. So it is easier to do as described in the SharePoint Developer Team Blog whereas in a one-liner can open link in a model window.
<div id="displayDiv"> <p> Please help us with our survey. Take our poll now! </ P> <input onclick = "javascript: SP.UI.ModalDialog.showModalDialog ({url: '.. / Lists / GBE / NewForm.aspx', title: 'User Survey'}); return false; "id =" btnVote "type =" button "value =" Vote "/> </ div>

Which approach would you choose? Post a comment with your solution.