SharePoint and Docx

Leave a comment

When you upload a docx to a document library, SharePoint adds custom column metadata to the document. For example: I’ve added 2 custom columns to a library. 1 Text field (CustomColumn1) and a dropdown column (CustomColumn2). Next I create an example docx document named “my_testdocument.docx”. I upload the testdocument to the document library and fill in the extra metadata:

Upload the docx document and fill in the custom metadata

Next I download the document to my desktop and change the docx extension to zip, so I can open the document. You can see that inside docx is completely xml:

docx to zip

I open the zip and look in the “customXml” folder for my custom columns. They appear in a file named “item2.xml”. Next I open the “item2.xml” file with an editor (in my case visual studio) and change the values of my custom column metadata:

change metadata values

After saving the file and renaming the file to “my_testdocument2.docx” I upload the edited file to the SharePoint Library:

new metadata

SharePoint adds the updated metadata to the custom Library columns.

ServerTemplate of a SharePoint Record Library

Leave a comment

For creating a SPDSiteDataQuery I needed the ServerTemplate of a SharePoint Record Library. Could not find a post about it, so here it is:

BaseType = 1
ServerTemplate = 1302

Eventreceiver that triggers on unzipping a SharePoint 2010 DocumentSet after routing

Leave a comment

I needed to automatically convert documents that are added to a Records Library to PDF. The documents are part of a DocumentSet when they are submitted to the record centre. They are routed to their final destination and after that they are unpacked (unzipped). The moment they are unzipped I wanted to convert them, so I thought as a trigger I could use the ItemAdded event for each document that was unzipped.

The ItemAdded eventreciever triggers when the documentset is added to the Record Library by the content router (so far so good), but when the DocumentSet is unpacked (unzipped) the ItemAdded eventreceiver is not triggered at all. Instead, to my surprise, for each document that is unzipped the ItemUpdated event is triggered. Unexpected, but it does the job.

Set maximum upload filesize SharePoint WCF service

Leave a comment

When I changed a SharePoint asmx webservice to a WCF service I ran into the problem that out-of-the-box you can only upload files (as bytestreams) with a maximum filesize of about 18 KB (which is not a lot). After some searching on the internet I found that the WCF endpoint settings should not be set in web.config, but that there is a convenience class “SPWcfServiceSettings”.

I use the featureinstalled method of the feature eventreceiver of the SharePoint WCF service to set the servicesettings.

wcf settings

Settings for WCF service

Please note that even if the name of your service has capitals, like “DMSService.svc”, you still need to reference your service in all lower case: “dmsservice.svc”. If your service is hosted in a folder for example “DMSServices/DMSService.svc” you need to reference your service without the folder path: “dmsservice.svc”.

Update “Created by”, “Modified by”, “Author” and “Editor” fields

Leave a comment

Last month I was working on a project which used a webservice to upload files to a SharePoint document Library. The webservice had to run under a service account, so the “Created by”, “Modified by”, “Author” and “Editor” fields always had the same value (like “Administrator”). I wanted the fields to have the value of the person that actually loads up/edits the file.

I eventually used the method below where “userName” is the name of the user that the fields should be filled with, “item” is the actual item that has been created/uploaded and “isCreation” indicates if the item is created (true) or updated (false).

You need submit the userName in your request message and the userName has to be known in SharePoint.

Method example