SharePoint 2010 + Kofax Express + Object reference not set to an instance of an object

I’ve been working with Kofax Express 2.0 recently to move documents from a scanner directly in to a SharePoint document library. I was using a custom list definition (created in Visual Studio) but was experiencing a strange error. If I created an instance of my list through the UI and then tried to scan from Kofax directly in to SharePoint, it was working no problem. However, if I tried to scan directly to SharePoint to the instance of the list created by the Visual Studio solution, I was getting the common error - “Object reference not set to an instance of an object”. There were no helpful logs on the Kofax or SharePoint end, and it was only through trial and error that I found the issue. I noticed that when the list was created through the UI, it was created with a URL of “/Document Library Name” whereas in my list instance definition in Visual Studio, I had given it a URL of “/Lists/Document Library Name”. It was the Lists part at the beginning which was causing an error. I don’t know why this caused Kofax to fail to find the library, but nevertheless, setting the URL in the list instance as just “/Document Library Name”, resolved the issue.

Read more

Can't alter server principal ‘dbo'

If you’ve encountered anything like this problem, then you may have had to update the permissions that a specific SQL login has. However, if the user you’re trying to edit is mapped to dbo, then you’re not allowed to make changes.

There are ways to do it, but you need a pretty thorough understanding of what you’re trying to achieve.

There’s a quick way around this using only the GUI. In SSMS, open the properties of the database(s) you need access to. In the ‘Files’ page, you’ll see the Owner of the database. This is quite likely the account you want to add additional permissions to. But since it’s mapped to dbo, you can’t. Therefore you update the owner of the database to something other than your login (e.g., sa). When you do this, you should then be able to add the required permissions to your login.

Read more

Painted lady butterfly timelapse

Painted lady butterfly timelapse showing a butterfly turning out of its chrysalis.

First experimentation with timelapse stuff. This was a crummy old webcam attached to my computer.

Apparently YouTube took offence at my choice of copyrighted music. Bastards.

SharePoint workflow + list item edit + value cannot be null

You may encounter a random error when using a custom Visual Studio SharePoint 2010 workflow. Everything appears OK, but when you go to edit the item that the workflow is running on, the EditForm fails to load and you see an error like:

`Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: s

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentNullException: Value cannot be null.
Parameter name: s]
System.IO.StringReader..ctor(String s) +10151478
System.Xml.XmlDocument.LoadXml(String xml) +51
Microsoft.SharePoint.Publishing.Internal.WorkflowUtilities.FlattenXmlToHashtable(String strXml) +90
...
`

Read more

Tip: Error occurred in deployment step Activate Features: Object not set to an instance of an object

Yet another SharePoint vagary. If you’re trying to deploy a feature and get the unhelpful error: “Error occurred in deployment step ‘Activate Features’: Object not set to an instance of an object” check the scope of the feature that you’re trying to deploy. I added a new feature to a project that had another working feature. Both were calling the Microsoft.Office.Workflow.Feature assembly but only one was failing and it was only after a lot of messing about that it turned out to be this innocuous little setting.

Read more

SharePoint 2010 + Associate workflow to Content Type in a feature

Quick tip: this plagued me for a while. You may develop a custom workflow which should only be associated with particular content types. You can deploy it to your site and then manually associate it to your content type. It’s possible to do this in code but the process isn’t as straight forward as it should be. Not to mention the fact that it’s infuriatingly hard to debug EventReceivers (“no symbols have been loaded” misery!).

Read more

SharePoint + Visual Studio + Get Current User

A frequently asked question in the MSDN forums is “how you can get access to the user who is interacting with your workflow?”. For example, the user modifying a task. The workflow is likely running in a different context and/or session to your browser session so there’s not an obvious tie-up.

However, in this scenario, you can get the login name of the person who modified the SharePoint task, via the Executor property of the OnTaskChanged event. Simply bind the Executor property to a string (e.g., “taskLastModifiedBy”) and whenever the task changes, SharePoint will copy the user ID to this property in the format of DOMAIN\LoginName. You can then get an SPUser object for that login name with, e.g.

SPUser user = workflowProperties.Web.AllUsers[taskLastModifiedBy];

Note: On a related subject, and the thing that prompted this post - if you’re trying to update a Person or Group field on your workflowProperties.Item, then you must pass it an SPUser object! This is bizarre, because other types of list (e.g, the task list) you can pass it a string and SharePoint will do the rest. I spent ages and all kinds of different things and always getting the “Invalid data has been used to update the list item. The field you are trying to update may be read only.” error. Annoying.

Read more

Tip: infopath comments and newline textbox

One method for persisting data in a SharePoint environment is the use of Infopath forms. Infopath stores data in your form in XML format. I have a form which has a “comments” box where people add new comments as they progressively update the form and a “consolidate comments” box which shows all previous comments*. However, Infopath forms don’t natively support appending new data to existing data - and new comments added may blow away any previous comments.

Read more

Visual Studio 2010 Workflow + Infopath 2010 forms - troubleshooting

Microsoft markets that Sharepoint Designer workflows are directly exportable to Visual Studio workflows. And in many ways, this is absolutely true. It’s trivial to create a .wsp from an SPD workflow and import it to VS. However, if you then inspect the workflow that has been created for you, a little concern would not be underestimated. If your SPD workflow was what you wanted, then you could be reasonably confident that its VS version would do the same job. But presumably your reason for importing to VS is because you need more control over the workflow in the longer term, in which case, you’re likely to be left underwhelmed by what the import process creates for you. Imagine creating a webpage in Microsoft Word and you’ll get the drift.

So when faced with a similar proposition, recreating the workflow in Visual Studio from scratch immediately became apparent as the best solution. After all, the intent and purpose of the workflow was clear; recreating it in VS ought to have been a doddle. However, to complicate matters, the SPD workflow used Infopath edit forms. This turned out to be easy in SPD, but non-trivial in Visual Studio. Getting an Infopath form to register with a VS workflow project requires various items, that VS may not do automatically for you.

Read more

Could not load web.config file. The given key was not present in the dictionary.

Quick hint about debugging SharePoint projects in Visual Studio 2010. You may find a bizarre error where deploying projects/solutions is fine, but trying to debug doesn’t work. You see an error alert with the text:

“Could not load the Web.config configuration file. Check the file for any malformed XML elements, and try again. The following error occurred: The given key was not present in the dictionary.”

Checking the Web.config shows no malformed XML at all. One thing to check into is the configuration of alternate access mappings in Central Administration. For debugging to work, the Site URL property of your SharePoint project must match the URL of the Default zone for your web application.

Read more