Sunday, June 30, 2013

SharePoint and Excel Properties step by step

In this blog I will describe how to create an Excel and publish data in SharePoint columns by a simple VB Script. This example is created in SharePoint 2013 and Excel 2013.

- Create a SharePoint Document Library and create the columns you want filled in by Excel;
- I created for this example the columns: Date, Amount and Total

- Upload a empty Excel Document with Macro enabled to the SharePoint Library

- Open the Excel document from your SharePoint site and add the Developer toolbar to Excel
- Now you need to make a note where you want to connect  the data. You need to count the cells. For Example if you want to place the data in A1 you count 1,1 or B1 you count 2,1 or C2 you count 3,2.

- In my example I will add the data to columns: Date B5 (2,5), Amount (2,6), Total (2,7)

- Click on the developer toolbar and Insert and select the Active X button

- Now select the button and right click (Properties)
- Change the value Name to UpdateButtom and Caption to Update SharePoint Properties. Close the window
- Double click the button to open the VB Editor.
- Add the following code:

Private Sub UpdateButtom_Click()
For Each Prop In ThisWorkbook.ContentTypeProperties
If Prop.Name = "Date" Then
Prop.Value = Cells(2, 5).Value
End If
Next Prop
End Sub

- For every other cell just add after Next Prop and before End Sub again the code starting with If Prop.Name so for my sheet the code would be:

Private Sub UpdateButtom_Click()
For Each Prop In ThisWorkbook.ContentTypeProperties
If Prop.Name = "Date" Then
Prop.Value = Cells(2, 5).Value
End If
If Prop.Name = "Amount" Then
Prop.Value = Cells(2, 6).Value
End If
If Prop.Name = "Total" Then
Prop.Value = Cells(2, 7).Value
End If
Next Prop
End Sub

- Now save the Excel as Macro Enabled as Template and use it in SharePoint as Content Type. When you open the Excel and fill in the properties and you click the button the Properties will be copied to SharePoint.



Monday, June 24, 2013

Show last Modified Documents on homepage SharePoint (Content Query)

In almost all the designs for customers I get the question to publish the most resent documents on the homepage. 

This can be done when the Publishing Feature on the site collection is activated.

- Edit the page
- Insert a new Web Part
- Select from the Content Rollup, Content Query
- Edit the Web Part
- At the Source select the site or the complete site collection to Query
- Select your content type (like Document Library) as List Type
- In my case I leave the Content Types set to All Content but you can filter this if you want
- At Additional Filters select Modified or Created and choose "is greater than or equal to"
- Select Custom Value for example -7 to show all documents older the 7 days
- At Appearance you can change the title of the box


When you Apply and save the page you see the last 15 documents. Off course you can do more customization with the web part but this is the basic setup.


Tuesday, June 4, 2013

Clear SharePoint Workflow cache

Sometimes SharePoint Workflows will hang or will not stared. To fix this you need to clear the cache of the Workflow directory on the SharePoint Servers.


Clear SharePoint cache.

Go to “C:\Documents and Settings\All Users\Application Data\Microsoft\SharePoint\Config\GUID” (in Windows Server 2003) or to c:\ProgramData\Microsoft\SharePoint\Config\GUID (in Windows Server 2008).

The procedure is simple (do it for every server):

1. Stop the Administration and Timer service
2. Delete all XML files in the directory (not the folder itself)
3. Open “Cache.ini” and write the number 1 instead of the existing number (you might want to make a note of it)
4. Start the services again
5. Wait for a minute or two and see if the folder starts to fill up with xml files. It is likely that it will contain less than before clearing it.
6. Check the cache.ini file. If it’s accessible and the number is considerable greater than 1 your cache has been properly initialized and chances are that your problems are now fixed. It didn’t fix my problem, so you may need to read on… (if you didn’t have the “888k” log entry mentioned above you probably have it now)

After this sometimes there is need to start new workflow on some item.