In some projects there was a need to run code on the client machine for interaction with SharePoint. If’ve realized this kind of applications as “ClickOnce” apps. It’s possible to deploy them as “SharePoint Solution Package”. If you do so the ClickOnce files can be deployed to every WFE. Updating the ClickOnce is easy.

Here I want to show you how to deploy a ClickOnce app als SharePoint Solution.

Let’s start.

1. Create your ClickOnce app. – If you have an existing one skip to step 5. – Otherwise continue reading. I’ll show you how to create a very simply ClickOnce.

Open Visual Studio 2010. Create a new project of type “Windows Forms Application” or “WPF Application”. I’ll use the first one and name the project “MyClickOnce”.

Design you app. – I drag 2 Label controls, 2 Checkbox controls and 2 Textbox controls to the surface. I do not change their names but their fonts

In my app I’d like to show the “running context”: locally started EXE or online started ClickOnce. Furthermore I’d like to show the URL if started online.

2. Open the Code view of the form.

First of all you need to add a assembly reference for “System.Web”!

Then insert this code. Maybe you need to correct the name of the controls.

The method “ParseParams” will be useful while developing the app and later running the app: This method is able to parse both “command line parameter” sources: URL and native (EXE). During development you maybe need to pass parameters to the app for testing purpose. Than you define this parameters in the “Debug” tab of the project properties.

Here is a screenshot of the app’s debug settings:

You see there is a parameter “Param1” follwed by “=” and it’s value. This is similar to URL style query string parameters. But you do not separate them with “&”! Instead use a single whitespace. – Later in the URL you will use “&” as normal!

Now just run the app!

Nice, isn’t it?

3. Now you need to configure the application to become a ClickOnce.

Open the Project Properties of your Windows Form App project.

Select the “Signing” tab and create a self signed certificate. Or use a valid Code Signature certificate.

Now switch to the “Publish” tab of the project settings.

Here you can change the settings as you need it. – I’ll leave it as is EXCEPT one setting: Click the “Options…” button and select “Manifests”. Check “Allow URL parameters to be passed to application”:

[If you do not set this the app will fail in the following line because “ActivationUri” will be null: “_url = ApplicationDeployment.CurrentDeployment.ActivationUri.ToString(); “]

The other settings:

Click “Publish Now”.

Than the project will be build and stored to the sub folder “Publish” of your project folder in the file system.

4. If you now try to run the app locally you may get this error:

This is caused by your ClickOnce publishing in the step before.

The resolve this open the project settings, select the “Security” tab and clear the checkbox “Enable Clickonce security settings”:

This you need to do after each ClickOnce publishing!

5. Now we create the SharePoint Solution Package.

In the Solution Explorer click on the solution item, click “Add” and click “New project”.

Now chooce “Empty SharePoint Project” and name it “MyClickonceDeployment”.

As local site I use “http://sharepoint.local/sites/clickonce”. It has to be a “Farm Solution”!!

Now create a “Module” project item. Name it “MyClickonce”.

Remove the file “Sample.txt”

6. Now open the solutions path in Windows Explorer.

Go into the folder of the Windows Forms Application. There go into the “Publish” folder.

Select the “.application” file of your ClickOnce app and select the “Application Files” folder. This items you need to copy. Just select “Copy” from the context menu or press Ctrl+C.

No open the folder of “MyClickonceDeployment” and go into the folder “MyClickonce”. There insert (paste) the selected items.

Now you folder should look like this:

In the “Application Files” folder you’ll see another folder “1_0_0_0” or with another version number. This version number will be increased by every ClickOnce publishing if you did not disable this function.

7. Back in the Visual Studio go into the Solution Explorer and click this icon:

This will show you all files in the project folder, not even project items.

Select the “MyClickonce” module project item. Maybe you need to click the icon:

You should see this:

Right click on “MyClickonce.application” and select “Include in project”. Right click on “MyClickonce_1_0_0_0” and select “Include in project”.

Now you need to edit the “Elements.xml” file of you module project item.

First of all add an attribute named “Path” to the “Module” tag. This will define the URL of your ClickOnce app. Select a unique name so that the solution won’t get in conflict with other solutions. You could choose a GUID here or use date and time:

Now you can remove the string “MyClickonce/” of the beginning of every “Path” attribute of the child nodes of the “Module” tag.

Of course you could build query strings in JavaScript to pass dynamically generated parameters to the ClickOnce!! This is charming and makes ClickOnce apps to become usefull in SharePoint development. You could create custom Ribbon menu items and call a ClickOnce app on click. As parameters you could pass ListID, Web URL, ItemID, … to the app! Very cool!

Worked fine for me when following your simple example and testing over our intranet but…. I have an authentication related problem with our prod environment where I want to ClickOnce deploy a WPF desktop app.

The users that need to download and update the desktop app using ClickOnce will be doing so via the Extranet address, as they do not use standard corporate build machines and thus do not log in to our Domain when starting their machines – only when prompted by SharePoint and choosing Windows Authentication do they provide user name and password.

Problem I have is that when accessing the ClickOnce .application file using the https url, dfsvc.exe fires up and gets a 403 forbidden when trying to access the file, clearly it doesn’t have the authentication token that IE has.

If you or any other SP experts out there have any advice or can suggest a workaround it would be much appreciated, thanks in advance.

DISCLAIMER

The informations on my blog are provided as is and I cannot guarantee that editing the registry or executing the provided code or provided scripts or doing other actions described in my articles will not cause serious damage. You use this information at your own risk! - I'm not responsible content on external sites.