Monday, 7 November 2016

The blog is back online

The blog have been offline for a couple of month now, because I had som issues with renewing my subscription of the domain.
All that is finally solved now and the blog is online and ready for new posts.

And new posts will come, since I have been worked with SharePoint Online, Office 365 and Azure for almost two years now.

Next week I'm joining ESPC16 i Vienna, so I'll hope to find time to write some posts from the conference.

Br Martin

Thursday, 10 November 2011

How to add ReCaptcha in SharePoint 2010

- and what are the challenges

I have resently added ReCaptcha in a SharePoint 2010 Solution.
The goal was to add extra security to an existing form in a web part.
I have the following assumptions:
- I have an existing Visual Studio Solution.
- I have a Project in the solution.
- I have added a Visual web part in the project.

Get Recaptcha
First of all I requested a key on the Recaptcha homepage and I downloaded the assembly (Recaptcha.dll) that I needed.
Sign up: ""
Download: ""

Add Recaptcha to my solution
The next thing was to get the assembly in to my Visual Studio solution.
In a project in my solution I created a folder called Dependencies and in this folder I added the Recaptcha.dll.

In my solution I wanted to add the dll to the Gac, and I did it like this:
- I double clicked on the Package folder in the project where I added the dll.

In the Package dialog I clicked on the link Advanced.

In the Advanced dialog I clicked Add -> Add Existing Assembly...
- Source Path: I located the file in the project folder. ("Dependencies\Recaptcha.dll")
- Deployment Target: GlobalAssemblyCache.
- Location: Recapture

I clicked "Click here to add a new item."
In the new item I added:
- Namespace: Recaptcha
- Assembyname: Recaptcha, Version=, Culture=neutral, PublicKeyToken=9afc4d65b28c38c2
- Safe: Checked
I Clicked OK.
Now the dll was added to the GAC the next time I deployed the wsp file.

Add ReCaptcha to the form
The next thing was to add the control to my form.
Before adding the ReCaptcha control to the form, I had to register the assembly, so I added the following code:

Then I added the control where I wanted it to be placed:

<recaptcha:RecaptchaControl ID="ReCaptcha" runat="server" PublicKey="***" PrivateKey="***" Theme="clean" />

PublicKey and PrivateKey was the ones I got from the ReCaptcha email tahat I got when I signed up for a key.

Now the challanges began
My challanges was:
1. No way to set the ErrorMessage on the Captcha object
2. An error in the Captcha will appear in the ValidationSummary, in english (ErrorMessage)

1. It was and is possible to create a custom translation, but it will not effect the ErrorMessage on the Captcha object. Instead there is another way to add a custom error message.
First you must add a label where you want the Captcha error to appear. I added a label with the ID="labelCaptchaError" and the error Text="An danish error message".
In the PageLoad add the following check to determine if the label control were going to be visible or not.

protectedvoid Page_Load(object sender, EventArgs e)
    labelCaptchaError.Visible = !ReCaptcha.IsValid;

Then as long as the captcha control is valid the error message wont be showed.
In the button_clicked event I added the same check, but right before I called the method ReCaptcha.Validate() to validate the control.
Now I can check if the user has entered the right Captcha code. if it is valid then do something else the error label is visible and the error message shown.

2. The english ErrorMessage will automatically be shown in the ValidationSummary and to avoid that, I added a ValidationGroup to all other controls including the submitbutton.
This is also why a have to call the Validate() method in the button event.

After performing these steps I have a form with a Captcha control and it works.
I hope U can use this example. I will the next time I have to add a Captcha to a Form.

Wednesday, 27 October 2010

The URL ... It may refer to a nonexistent file or folder, or refer to a valid file or folder that is not in the current Web"

Today I got this error and it took me a while before I found the solution.

The error occured when I was trying to upload a Word document to a Document Library. I did not even get the form where I could add the required data. Meanwhile creating a new document was no problem.
The Docuemnt Library was a default library, where I had programmatically added a few columns.

I began to start focusing on these column, and I deleted them one after another an then, BINGO! When I deleted a SPFieldBoolean column, I could suddenly upload documents.
This columns default property was set to "Yes" and this was all wrong.
Even though its a string property it shall be set to either 0 or 1 meaning no and yes.

Lesson learned.

Friday, 3 September 2010

Get Web template and configuration id

Here is an easy way to get the name of the Web Template and the Configuration id from a SPWeb.

string template = web.WebTemplate; // gives you the name of the Web Template
int configuratuionId = web.Configuration; // gives you the configutaion id

Thats all ;-)

Monday, 23 August 2010

Add ListView Web Part to Site Template

My challange was to add a ListView Web Part in my Site Template. The problem was, that the ListView Web Part is not a "normal" Web Part, but a view of the list i want to show.

This means, that you can't add it in the AllUsersWebPart section as you would normally do. Instead you can add it just after that section.

The code looks like this:

1. First I have added a list in the configuration section.

2. Then I reference a module in the module section.

3. At last, I add the view to the module, just like this.

BaseViewID is the index of the view in the list/library.

I hope you can use this example, and it will save you som time!

Wednesday, 28 January 2009

GetUserProfileByName Profile properties

When working with the UserProfileService webservice there are a number of Profile properties you can get when you use the GetUserProfileByName method.

I have listed the Profile properties in the buttom of this post.

If you have added new Profile properties in Central Administration - Shared Services - User Profiles and properties, you can get them as well, just remember to use the Name instead of Display Name.
You can see the name of the property following the link above and select View Profile Properties and select Edit on one of the properties. Here you can see the Name.

How to use the webservice follow this link:

Profile properties:

InfoPath Rules DataValidation

If you have an Control, ex. a TextBoxt you can validate the text using a pattern.

  1. Doubleclick on the TextBox or left click and choose Options
  2. Click DataValidation
  3. Click Add
  4. In the first dropdown select the TextBox (selected as default)
  5. In the second dropdown select "Does not match pattern"
  6. In the third dropdown select Userdefined pattern and enter the pattern.

Here is a growing list of patterns.

Email: (\p{L}+_*-*\p{L}*\d*\.?)+@(\p{L}+-*\p{L}*\.?)+
It's not perfect, because it allows and, but it does allow and

Thursday, 15 January 2009

Eventhandler associated with incoming email

Just a little reminder:

If you want to debug an eventhandler associated with incoming email, you need to connect to the OWSTimer.exe instead of w3wp.exe, as the OWSTimer takes care of the email and the event handler.