tag:blogger.com,1999:blog-44638982507763786082024-03-13T05:25:06.078+01:00Koen van der Linden's SharePoint BlogArticles about exciting challenges I come across when implementing SharePoint 2010/2013, Android apps and IOT related projects.Koen van der Lindenhttp://www.blogger.com/profile/09745561653129473651noreply@blogger.comBlogger31125tag:blogger.com,1999:blog-4463898250776378608.post-18632853033552288262017-03-22T22:24:00.001+01:002017-03-22T22:24:59.524+01:00Getting .NET Core Web API to run on Ubuntu Raspberry Pi<p>These steps have been tested on a Raspberry Pi with Linux Ubuntu 16.04. The Web API project is created on Windows 10 machine. <br> <h2>Prepare Windows development machine</h2> <p>* Install Install .NET Core 2.0 SDK from <a href="https://github.com/dotnet/cli/tree/master">https://github.com/dotnet/cli/tree/master</a><br>After installation check the version by running the following dotnet command in a Command Prompt.<br>dotnet --info<br>Output will be like:<br>.NET Command Line Tools (2.0.0-preview1-005448) <p>Product Information:<br>Version: 2.0.0-preview1-005448<br>Commit SHA-1 hash: f8c3c4a030 <p>Runtime Environment:<br>OS Name: Windows<br>OS Version: 10.0.14393<br>OS Platform: Windows<br>RID: win10-x64<br>Base Path: C:\Program Files\dotnet\sdk\2.0.0-preview1-005448\ <p>* Add development nuget sources by adding key values to the nuget.config. Nuget will now be able to get the latest packages that are under development:<br>Open C:\Users\xxxx\AppData\Roaming\NuGet\Nuget.config <p>add the keys:<br><add key="aspnetcore-dev" value="<a href="https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json"">https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json"</a> /><br><add key="dotnet-core" value="<a href="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json"">https://dotnet.myget.org/F/dotnet-core/api/v3/index.json"</a> /><br><add key="dotnet-corefxlab" value="<a href="https://dotnet.myget.org/F/dotnet-corefxlab/api/v3/index.json"">https://dotnet.myget.org/F/dotnet-corefxlab/api/v3/index.json"</a> /><br><add key="aspnetcore-ci-dev" value="<a href="https://dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json"">https://dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json"</a> /> <br> <h2>Prepare Raspberry Pi</h2> <p>* Download Ubuntu Mate 16.04 from <a href="https://ubuntu-mate.org/raspberry-pi/">https://ubuntu-mate.org/raspberry-pi/</a> and install it on your Raspberry Pi. <p>* Install all of the required libraries for .NET Core:<br>sudo apt-get install libunwind8 libunwind8-dev gettext libicu-dev liblttng-ust-dev libcurl4-openssl-dev libssl-dev uuid-dev unzip <p>* Download and install .NET Core runtime components for Ubuntu 16.04 for ARM 32 (check: <a href="https://github.com/dotnet/core-setup#daily-builds)">https://github.com/dotnet/core-setup#daily-builds)</a>. You should be able to do:<br>wget <a href="https://dotnetcli.blob.core.windows.net/dotnet/master/Binaries/Latest/dotnet-ubuntu.16.04-arm.latest.tar.gz">https://dotnetcli.blob.core.windows.net/dotnet/master/Binaries/Latest/dotnet-ubuntu.16.04-arm.latest.tar.gz</a><br>sudo mkdir -p /usr/share/dotnet<br>sudo tar -xvf dotnet-ubuntu.16.04-arm.latest.tar.gz -C /usr/share/dotnet/<br>sudo ln -sf /usr/share/dotnet/dotnet /usr/bin/dotnet <p>* determine dotnetcore runtime version by running command 'dotnet --info'<br>I my case it will show a version of 2.0.0-beta-001791-00 <br>We will use this version information later on in the process. <p>* create directory ‘mywebapi’ in your home directory. In later step we will publish the files to this directory. <br> <h2>Create Web API Project on development machine</h2> <p>* create a .NET Core Web API project name ‘mywebapi’ by running command: dotnet new webapi -n mywebapi<br>Project file will look like:<br><Project Sdk="Microsoft.NET.Sdk.Web"><br> <PropertyGroup><br> <TargetFramework>netcoreapp1.0</TargetFramework><br> </PropertyGroup> <p> <ItemGroup><br> <Folder Include="wwwroot\" /><br> </ItemGroup> <p> <ItemGroup><br> <PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" /><br> <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" /><br> <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" /><br> </ItemGroup><br></Project> <p>* Modify project file to:<br>- enable publishing for ubuntu 16.04. Add <RuntimeIdentifiers>ubuntu.16.04-arm</RuntimeIdentifiers><br>- target .NET Core 2.0. Change TargetFramework into <TargetFramework>netcoreapp2.0</TargetFramework><br>- make sure packages and publish will be for the .NET Core framework running on Raspberry Pi. In my case this was 2.0.0-beta-001791-00, so add node <RuntimeFrameworkVersion>2.0.0-beta-001791-00</RuntimeFrameworkVersion><br>- add reference to make sure the libvu.so is being deployed. This was previously part of on of the standard Microsoft.AspNetCore package, however it was remove. So a reference to the libuv package. Add: <PackageReference Include="Libuv" Version="1.10.0-preview1-22036" /> <p>The final project file:<br><Project Sdk="Microsoft.NET.Sdk.Web"><br> <PropertyGroup><br> <TargetFramework>netcoreapp2.0</TargetFramework><br> <RuntimeFrameworkVersion>2.0.0-beta-001791-00</RuntimeFrameworkVersion><br> <RuntimeIdentifiers>ubuntu.16.04-arm</RuntimeIdentifiers><br> </PropertyGroup> <p> <ItemGroup><br> <Folder Include="wwwroot\" /><br> </ItemGroup> <p> <ItemGroup><br> <PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" /><br> <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" /><br> <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" /><br> <PackageReference Include="Libuv" Version="1.10.0-preview1-22036" /><br> </ItemGroup><br></Project> <p>* Get the latest packages by using the dotnet restore command<br>dotnet restore <p>* Publish the Web API project for Ubuntu by using –r and the RuntimeIdentifier that was in the project file.<br>dotnet publish -r ubuntu.16.04-arm<br>This command published files to the \bin\Debug\netcoreapp2.0\ubuntu.16.04-arm\publish\ folder. <p>* copy files from build output (\bin\Debug\netcoreapp2.0\ubuntu.16.04-arm\publish) to the Raspberry Pi.<br>You can used pscp (that is available when Putty is installed). Open Command Prompt, go to \bin\Debug\netcoreapp2.0\ubuntu.16.04-arm\ folder. Run the following command to copy all files (including all (sub)directories) to the Raspberry Pi into the mywebapi directory. <br>pscp -l <raspberry-loginname> -scp -r publish <ip-address>:mywebapi <br> <h2>Start the Web API application on Raspberry Pi</h2> <p>* On Raspberry Pi go to the mywebapi directory. Run 'dotnet mywebapi.dll' to start the Web API application.<br>Output:<br>Hosting environment: Production<br>Content root path: /home/someusername/publish/publish<br>Now listening on: <a href="http://localhost:5000">http://localhost:5000</a><br>Application started. Press Ctrl+C to shut down. <p>* To test the Web API service do a wget to ValuesController that is part of the sample Web API project.<br>wget <a href="http://localhost:5000/api/values">http://localhost:5000/api/values</a> <p>it will create a file values containing the response, in this case: <br>["value1","value2"]</p>Koen van der Lindenhttp://www.blogger.com/profile/09745561653129473651noreply@blogger.com0tag:blogger.com,1999:blog-4463898250776378608.post-54145738808622756322015-11-02T21:07:00.000+01:002015-11-02T21:08:36.337+01:00How to authenticate your Android App to SharePoint 2013<p>This blog post shows how to authenticate against an on premise SharePoint 2013 environment and do a simple REST call to retrieve the title of the root web. The SharePoint environment is configured to authenticate with Forms Based Authentication and runs on https.</p> <p>Various other posts about an Android app authenticating to SharePoint are using a WebView solution. But I didn't want the user to use a integrated web view, but just do the authentication in code. The main point is to get hold of the FedAuth token from a cookie and pass the token back into all calls to SharePoint.</p> <p>The main steps to authenticate and do a REST call to SharePoint are as follows:<br>1- Configure the CookieManager<br>2- Authenticate user: Start a AsyncTask to do a SOAP request to <a href="https://sharepoint.dev/_vti_bin/authentication.asmx">https://sharepoint.dev/_vti_bin/authentication.asmx</a><br>3- The cookie returned in step 2 will contain the FedAuth token.<br>4- the REST call: Start a HttpURLConnection to do a GET request to <a href="https://sharepoint.dev/_api/web/title">https://sharepoint.dev/_api/web/title</a><br> Make sure this HttpURLConnection contains the FedAuth token in Cookie.<br>5- Parse JSON result</p> <p>Now some more details please…</p> <p><strong>1- Configure the CookieManager</strong><br>In Frament: onCreateView. Create a CookieManager that handles cookies within the VM. Make sure to set it to default. The network calls will use this CookieManager. That includes the CookieStore which will contain the cookies received by network calls.</p> <div id="codeSnippetWrapper" style="font-size: 8pt; overflow: auto; cursor: text; border-top: silver 1px solid; font-family: 'Courier New', courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; border-left: silver 1px solid; margin: 20px 0px 10px; line-height: 12pt; padding-right: 4px; background-color: #f4f4f4"> <div id="codeSnippet" style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum1" style="color: #606060"> 1:</span> CookieHandler cookieHandler = CookieHandler.getDefault();</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum2" style="color: #606060"> 2:</span> <span style="color: #0000ff">if</span> (cookieHandler==null) {</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum3" style="color: #606060"> 3:</span> CookieManager cookieManager = <span style="color: #0000ff">new</span> CookieManager();</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum4" style="color: #606060"> 4:</span> CookieHandler.setDefault(cookieManager);</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum5" style="color: #606060"> 5:</span> }</pre><!--CRLF--></div></div>
<p><br><strong>2- Authenticate user</strong><br>Doing a SOAP call to https://sharepoint.dev/_vti_bin/authentication.asmx<font color="#222222"> in </font>AsyncTask, doInBackground.</p>
<p>Line 1-4: various SOAP settings<br>Line 6/7, 12/13: username and password<br>Line 24: doing the SOAP call</p>
<div id="codeSnippetWrapper" style="font-size: 8pt; overflow: auto; cursor: text; border-top: silver 1px solid; font-family: 'Courier New', courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; border-left: silver 1px solid; margin: 20px 0px 10px; line-height: 12pt; padding-right: 4px; background-color: #f4f4f4">
<div id="codeSnippet" style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum1" style="color: #606060"> 1:</span> String SOAP_ACTION1 = <span style="color: #006080">"http://schemas.microsoft.com/sharepoint/soap/Login"</span>;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum2" style="color: #606060"> 2:</span> String NAMESPACE = <span style="color: #006080">"http://schemas.microsoft.com/sharepoint/soap/"</span>;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum3" style="color: #606060"> 3:</span> String METHOD_NAME1 = <span style="color: #006080">"Login"</span>;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum4" style="color: #606060"> 4:</span> String AuthURL = <span style="color: #006080">"https://sharepoint.dev/_vti_bin/authentication.asmx"</span>;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum5" style="color: #606060"> 5:</span> </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum6" style="color: #606060"> 6:</span> String username = <span style="color: #006080">"koenvanderlinden"</span>;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum7" style="color: #606060"> 7:</span> String password = <span style="color: #006080">"P@ssw0rd"</span>;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum8" style="color: #606060"> 8:</span> </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum9" style="color: #606060"> 9:</span> SoapObject request = <span style="color: #0000ff">new</span> SoapObject(NAMESPACE, METHOD_NAME1);</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum10" style="color: #606060"> 10:</span> </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum11" style="color: #606060"> 11:</span> <span style="color: #008000">//insert username and password to SoapEnvelope</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum12" style="color: #606060"> 12:</span> request.addProperty(<span style="color: #006080">"username"</span>, username);</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum13" style="color: #606060"> 13:</span> request.addProperty(<span style="color: #006080">"password"</span>, password);</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum14" style="color: #606060"> 14:</span> </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum15" style="color: #606060"> 15:</span> <span style="color: #008000">//Declare the version of the SOAP request</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum16" style="color: #606060"> 16:</span> SoapSerializationEnvelope envelope = <span style="color: #0000ff">new</span> SoapSerializationEnvelope(SoapEnvelope.VER11);</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum17" style="color: #606060"> 17:</span> </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum18" style="color: #606060"> 18:</span> envelope.setOutputSoapObject(request);</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum19" style="color: #606060"> 19:</span> envelope.dotNet = true;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum20" style="color: #606060"> 20:</span> </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum21" style="color: #606060"> 21:</span> <span style="color: #0000ff">try</span> {</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum22" style="color: #606060"> 22:</span> HttpTransportSE androidHttpTransport = <span style="color: #0000ff">new</span> HttpTransportSE(AuthURL);</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum23" style="color: #606060"> 23:</span> </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum24" style="color: #606060"> 24:</span> <span style="color: #008000">// do the SoapCall</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum25" style="color: #606060"> 25:</span> androidHttpTransport.call(SOAP_ACTION1, envelope, null);</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum26" style="color: #606060"> 26:</span> <span style="color: #008000">// At this point the CookieManager will containt a cookie that has the FedAuth token.</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum27" style="color: #606060"> 27:</span> </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum28" style="color: #606060"> 28:</span> } <span style="color: #0000ff">catch</span> (Exception e) {</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum29" style="color: #606060"> 29:</span> Log.v(LOG_TAG, e.toString());</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum30" style="color: #606060"> 30:</span> e.printStackTrace();</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum31" style="color: #606060"> 31:</span> }</pre><!--CRLF--></div></div>
<p><strong>3- Inspect cookies<br></strong>After the call androidHttpTransport.call() (line 22) the CookieManager will contain the cookies, including the FedAuth token. <br>To inspect the cookies add the following lines:</p>
<div id="codeSnippetWrapper" style="font-size: 8pt; overflow: auto; cursor: text; border-top: silver 1px solid; font-family: 'Courier New', courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; border-left: silver 1px solid; margin: 20px 0px 10px; line-height: 12pt; padding-right: 4px; background-color: #f4f4f4">
<div id="codeSnippet" style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum1" style="color: #606060"> 1:</span> <span style="color: #008000">// check cookies</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum2" style="color: #606060"> 2:</span> CookieManager cookieManager = (CookieManager)CookieHandler.getDefault();</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum3" style="color: #606060"> 3:</span> List<HttpCookie> cookies = cookieManager.getCookieStore().getCookies();</pre><!--CRLF--></div></div>
<p> <br><strong>4- the REST call: </strong></p>
<p>Line 4: Set REST url to get web title<br>Line 7: Create HttpUrlConnection<br>Line 10: Add application/json;odata=verbose to “Accept” header to get response in JSON format.<br>Line 11: Start the HttpURLConnection to do a GET request</p>
<p>The HttpURLConnection will use the CookieManager that is set as default. The CookieManager contains the CookieStore, which contains all cookies. Because the HttpURLConnection is doing a request to domain sharepoint.dev, the cookies will be added to the request that match on that domain. In this case the FedAuth cookie matches and is added to the request.</p>
<div id="codeSnippetWrapper" style="font-size: 8pt; overflow: auto; cursor: text; border-top: silver 1px solid; font-family: 'Courier New', courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; border-left: silver 1px solid; margin: 20px 0px 10px; line-height: 12pt; padding-right: 4px; background-color: #f4f4f4">
<div id="codeSnippet" style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum1" style="color: #606060"> 1:</span> HttpURLConnection urlConnection;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum2" style="color: #606060"> 2:</span> BufferedReader reader;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum3" style="color: #606060"> 3:</span> </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum4" style="color: #606060"> 4:</span> Uri uri = Uri.parse(<span style="color: #006080">"https://sharepoint.dev/_api/web/title"</span>);</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum5" style="color: #606060"> 5:</span> URL url = <span style="color: #0000ff">new</span> URL(uri.toString());</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum6" style="color: #606060"> 6:</span> </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum7" style="color: #606060"> 7:</span> urlConnection = (HttpURLConnection) url.openConnection();</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum8" style="color: #606060"> 8:</span> urlConnection.setRequestMethod(<span style="color: #006080">"GET"</span>);</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum9" style="color: #606060"> 9:</span> <span style="color: #008000">// we need JSON formatted result</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum10" style="color: #606060"> 10:</span> urlConnection.setRequestProperty(<span style="color: #006080">"Accept"</span>, <span style="color: #006080">"application/json;odata=verbose"</span>);</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum11" style="color: #606060"> 11:</span> urlConnection.connect();</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum12" style="color: #606060"> 12:</span> </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum13" style="color: #606060"> 13:</span> <span style="color: #008000">// Read the input stream into a String</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum14" style="color: #606060"> 14:</span> InputStream inputStream = urlConnection.getInputStream();</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum15" style="color: #606060"> 15:</span> StringBuffer buffer = <span style="color: #0000ff">new</span> StringBuffer();</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum16" style="color: #606060"> 16:</span> <span style="color: #0000ff">if</span> (inputStream == null) {</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum17" style="color: #606060"> 17:</span> <span style="color: #008000">// Nothing to do.</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum18" style="color: #606060"> 18:</span> <span style="color: #0000ff">return</span> null;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum19" style="color: #606060"> 19:</span> }</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum20" style="color: #606060"> 20:</span> reader = <span style="color: #0000ff">new</span> BufferedReader(<span style="color: #0000ff">new</span> InputStreamReader(inputStream));</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum21" style="color: #606060"> 21:</span> </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum22" style="color: #606060"> 22:</span> String line;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum23" style="color: #606060"> 23:</span> <span style="color: #0000ff">while</span> ((line = reader.readLine()) != null) {</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum24" style="color: #606060"> 24:</span> <span style="color: #008000">// Since it's JSON, adding a newline isn't necessary (it won't affect parsing)</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum25" style="color: #606060"> 25:</span> <span style="color: #008000">// But it does make debugging a *lot* easier if you print out the completed</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum26" style="color: #606060"> 26:</span> <span style="color: #008000">// buffer for debugging.</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum27" style="color: #606060"> 27:</span> buffer.append(line + <span style="color: #006080">"\n"</span>);</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum28" style="color: #606060"> 28:</span> }</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum29" style="color: #606060"> 29:</span> </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum30" style="color: #606060"> 30:</span> <span style="color: #0000ff">if</span> (buffer.length() == 0) {</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum31" style="color: #606060"> 31:</span> <span style="color: #008000">// Stream was empty. No point in parsing.</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum32" style="color: #606060"> 32:</span> <span style="color: #0000ff">return</span> null;</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum33" style="color: #606060"> 33:</span> }</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum34" style="color: #606060"> 34:</span> </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum35" style="color: #606060"> 35:</span> <span style="color: #008000">// JSON result</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum36" style="color: #606060"> 36:</span> String restResult = buffer.toString();</pre><!--CRLF--></div></div>
<p><strong>5- Parse JSON result</strong></p>
<div id="codeSnippetWrapper" style="font-size: 8pt; overflow: auto; cursor: text; border-top: silver 1px solid; font-family: 'Courier New', courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; border-left: silver 1px solid; margin: 20px 0px 10px; line-height: 12pt; padding-right: 4px; background-color: #f4f4f4">
<div id="codeSnippet" style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum1" style="color: #606060"> 1:</span> <span style="color: #008000">// parse JSON result</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum2" style="color: #606060"> 2:</span> JSONObject jsonResult = <span style="color: #0000ff">new</span> JSONObject(restResultString).getJSONObject(<span style="color: #006080">"d"</span>);</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum3" style="color: #606060"> 3:</span> title = jsonResult.getString(<span style="color: #006080">"Title"</span>);</pre><!--CRLF--></div></div>
<p><strong>Additional Information<br></strong>This code makes use of the <a href="http://simpligility.github.io/ksoap2-android/index.html">ksoap2-android</a> library. The Gradle configuratoin has been changes to include ksoap2 library by adding the following parts:</p>
<p>Add: repositories to android.buildTypes<br> repositories {<br> maven { url '<a href="https://oss.sonatype.org/content/repositories/ksoap2-android-releases/'">https://oss.sonatype.org/content/repositories/ksoap2-android-releases/'</a> }<br> }<br>Add: compile 'com.google.code.ksoap2-android:ksoap2-android:3.1.1' to dependencies.</p>
<p>Sample gradle:</p>
<div id="codeSnippetWrapper" style="font-size: 8pt; overflow: auto; cursor: text; border-top: silver 1px solid; font-family: 'Courier New', courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; border-left: silver 1px solid; margin: 20px 0px 10px; line-height: 12pt; padding-right: 4px; background-color: #f4f4f4">
<div id="codeSnippet" style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum1" style="color: #606060"> 1:</span> apply plugin: <span style="color: #006080">'com.android.application'</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum2" style="color: #606060"> 2:</span> </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum3" style="color: #606060"> 3:</span> android {</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum4" style="color: #606060"> 4:</span> compileSdkVersion 23</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum5" style="color: #606060"> 5:</span> buildToolsVersion <span style="color: #006080">"23.0.1"</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum6" style="color: #606060"> 6:</span> </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum7" style="color: #606060"> 7:</span> defaultConfig {</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum8" style="color: #606060"> 8:</span> applicationId <span style="color: #006080">"nl.idoconsultancy.androidauthsp"</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum9" style="color: #606060"> 9:</span> minSdkVersion 21</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum10" style="color: #606060"> 10:</span> targetSdkVersion 22</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum11" style="color: #606060"> 11:</span> versionCode 1</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum12" style="color: #606060"> 12:</span> versionName <span style="color: #006080">"1.0"</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum13" style="color: #606060"> 13:</span> }</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum14" style="color: #606060"> 14:</span> buildTypes {</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum15" style="color: #606060"> 15:</span> release {</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum16" style="color: #606060"> 16:</span> minifyEnabled false</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum17" style="color: #606060"> 17:</span> proguardFiles getDefaultProguardFile(<span style="color: #006080">'proguard-android.txt'</span>), <span style="color: #006080">'proguard-rules.pro'</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum18" style="color: #606060"> 18:</span> }</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum19" style="color: #606060"> 19:</span> repositories {</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum20" style="color: #606060"> 20:</span> maven { url <span style="color: #006080">'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/'</span> }</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum21" style="color: #606060"> 21:</span> }</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum22" style="color: #606060"> 22:</span> }</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum23" style="color: #606060"> 23:</span> }</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum24" style="color: #606060"> 24:</span> </pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum25" style="color: #606060"> 25:</span> dependencies {</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum26" style="color: #606060"> 26:</span> compile fileTree(dir: <span style="color: #006080">'libs'</span>, include: [<span style="color: #006080">'*.jar'</span>])</pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum27" style="color: #606060"> 27:</span> compile <span style="color: #006080">'com.android.support:appcompat-v7:23.0.1'</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum28" style="color: #606060"> 28:</span> compile <span style="color: #006080">'com.android.support:design:23.0.1'</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum29" style="color: #606060"> 29:</span> compile <span style="color: #006080">'com.google.code.ksoap2-android:ksoap2-android:3.1.1'</span></pre><!--CRLF--><pre style="border-top-style: none; font-size: 8pt; overflow: visible; border-left-style: none; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum30" style="color: #606060"> 30:</span> }</pre><!--CRLF--></div></div> Koen van der Lindenhttp://www.blogger.com/profile/09745561653129473651noreply@blogger.com9tag:blogger.com,1999:blog-4463898250776378608.post-12369248920836120632014-10-17T11:33:00.000+02:002014-10-17T11:32:49.770+02:00Operating your Hue remotely using Hue Remote API – a working Proof of Concept<h4>Introduction</h4> <p>To operate your Hue system on local network you can send REST based messages like described in the <a href="http://developers.meethue.com/">Philips hue API</a> to your Hue bridge. However if you want to do this in your custom application over the internet you have a problem. No API, no official documentation about how to sent messages through the <a href="http://www.meethue.com/">Hue Portal</a> that forwards it to your Hue bridge. </p> <p>This blog post will show how you can send messages to your Hue bridge over the internet (without using port forwards). In this proof of concept I reuse the access token of <a href="https://ifttt.com/">IFTTT</a>. The code samples are in C#, however you could make the same REST calls using the language of your choice.</p> <p>BTW: I assume you have an account on the Hue portal and that you registered your Hue bridge.</p> <h4>What others write about this topic</h4> <p>Just a few people have some information about this like:<br><a title="http://blog.paulshi.me/technical/2013/11/27/Philips-Hue-Remote-API-Explained.html" href="http://blog.paulshi.me/technical/2013/11/27/Philips-Hue-Remote-API-Explained.html">http://blog.paulshi.me/technical/2013/11/27/Philips-Hue-Remote-API-Explained.html</a><br><a href="http://www.dhanjani.com/docs/Hacking%20Lighbulbs%20Hue%20Dhanjani%202013.pdf">Hacking Lightbulbs: Security Evaluation of the Philips Hue Personal Wireless Lighting System</a> by <a href="http://www.dhanjani.com/about.html">Nitesh Dhanjani</a><br><a href="http://stackoverflow.com/questions/19900657/how-to-connect-backend-service-with-philips-hue-bridge-remotely">http://stackoverflow.com/questions/19900657/how-to-connect-backend-service-with-philips-hue-bridge-remotely</a></p> <p>I investigated some of the findings from above resources. The parts about the getting the access token is not working, it’s probably out of date because of changes to the Hue Portal. So if you don’t have an access token you cannot send commands to the Hue Portal.</p> <h4></h4> <h4>Local REST Messages</h4> <p>Sending a REST based message to your local bridge is done by sending a http request in the following format.</p> <table cellspacing="0" cellpadding="2" width="603" border="0"> <tbody> <tr> <td valign="top" width="200">URL</td> <td valign="top" width="401">http://<your bridge ip>/api/<username>/<some resource></td></tr> <tr> <td valign="top" width="200">Method</td> <td valign="top" width="401">GET/PUT/POST/DELETE</td></tr> <tr> <td valign="top" width="200">Body</td> <td valign="top" width="401">JSON formatted data</td></tr></tbody></table> <p>To turn on light 1 you will send a message like:</p> <table cellspacing="0" cellpadding="2" width="602" border="0"> <tbody> <tr> <td valign="top" width="200">URL</td> <td valign="top" width="400">/api/<username>/lights/1/state</td></tr> <tr> <td valign="top" width="200">Method</td> <td valign="top" width="400">PUT</td></tr> <tr> <td valign="top" width="200">Body</td> <td valign="top" width="400">{<br>“on”: true<br>}</td></tr></tbody></table> <p></p> <h4>Remote REST Message</h4> <p>Now it gets interesting. Sending a message to your bridge through the Hue Portal is a bit different. You should always use POST and send the request to the Hue portal. It should also include a valid access token. The body contains a clipmessage which contains a clipCommand that encapsulates the JSON command you normally sent to your bridge (in local network mode).</p> <p>The format is as follows:</p> <table cellspacing="0" cellpadding="2" width="603" border="0"> <tbody> <tr> <td valign="top" width="200">URL</td> <td valign="top" width="401">https://www.meethue.com/api/sendmessage?token=<AccessToken></td></tr> <tr> <td valign="top" width="200">Method</td> <td valign="top" width="401">always POST</td></tr> <tr> <td valign="top" width="200">Body</td> <td valign="top" width="401">clipmessage=<JSON formatted clipCommand><br><br>clipCommand==><br>{<br> “clipCommand” :<br> {<br> “url”: “api/0/<some resource>”,<br> “method”: “GET/PUT/POST/DELETE”,<br> “body”: JSON formatted data<br> }<br>}</td></tr> <tr> <td valign="top" width="200">Header</td> <td valign="top" width="401">encoding: UFT-8<br>application/x-www-form-urlencoded</td></tr></tbody></table> <p>Note: the url in clipCommand uses ‘0’ what in a local scenario would be the username.</p> <p>Below an example of a command that will turn on light 1.</p> <table cellspacing="0" cellpadding="2" width="604" border="0"> <tbody> <tr> <td valign="top" width="200">URL</td> <td valign="top" width="402">https://www.meethue.com/api/sendmessage?token=<AccessToken></td></tr> <tr> <td valign="top" width="200">Method</td> <td valign="top" width="402">POST</td></tr> <tr> <td valign="top" width="200">Body</td> <td valign="top" width="402">clipmessage=<br>{<br> “clipCommand” :<br> {<br> “url”: “/api/0/lights/1/state”,<br> “method”: “PUT”,<br> “body”:<br> { “on”: true }<br> }<br>}</td></tr></tbody></table> <p></p> <p>To retrieve the status of the Hue system you need to sent a message as follows:</p> <table cellspacing="0" cellpadding="2" width="603" border="0"> <tbody> <tr> <td valign="top" width="200">URL</td> <td valign="top" width="401"><a href="https://www.meethue.com/api/getbridge?token=<AccessToken">https://www.meethue.com/api/getbridge?token=<AccessToken</a>></td></tr> <tr> <td valign="top" width="200">Method</td> <td valign="top" width="401">GET</td></tr></tbody></table> <p>The result will be a JSON string representing the current state of your Hue system.</p> <h4>AccessToken</h4> <p>The biggest challenge in all this is to obtain a valid access token. In the next step I’m going to get the access token that <a href="https://ifttt.com/">IFTTT</a> is using. But you could also use the access token of the official <a href="https://itunes.apple.com/us/app/philips-hue/id557206189?mt=8">Philips Hue app</a>.</p> <p>Steps:</p> <p>1- Go to <a href="https://ifttt.com/">IFTTT</a></p> <p>2- Search for Channel ‘Philips Hue’</p> <p>3- Activate Channel, this will bring you to the Hue Portal and log you in, and ask you to trust IFTTT. Click ‘Yes’. The Hue Portal will generate an access token and IFTTT will use that access token to send command to your Hue bridge.</p> <p>4- When channel is activated logon to <a href="http://www.meethue.com/">Hue Portal</a></p> <p>5- Go to ‘Settings’</p> <p>6- Click on ‘My Apps’ and you will see a list of apps you trusted for accessing your Hue bridge.</p> <p><a href="http://lh6.ggpht.com/-GA1VitmKP1w/VAmZUfqz3xI/AAAAAAAAAP4/N9_zXxWjA10/s1600-h/image%25255B3%25255D.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="image" src="http://lh6.ggpht.com/-0mrTh4UrxQQ/VAmZUtZ-GFI/AAAAAAAAAP8/LNFFxD8eY8c/image_thumb%25255B1%25255D.png?imgmax=800" width="216" height="123"></a> </p> <p>7- Copy the link of the ‘(De-activate)’ link. It will contain the access token. Here’s an example of my token: https://www.meethue.com/en-us/user/preferencesappsrevoke?tokenId=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaTT0%3D<br>The access token you should send in the remote message should be: “aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaTT0=” (without the double quotes and make sure to URL encode the whole thing).</p> <p>BTW: If you revoke the access token by clicking ‘De-activate’ the access token cannot be used anymore. You will get a JSON response containing the message “I don't know that token”.</p> <p></p> <h4>Code samples</h4> <p>We now have the message structure and the access token. We can now put this together in a C# sample.</p> <div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: 'Courier New', courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4"> <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum1" style="color: #606060"> 1:</span> dynamic command = <span style="color: #0000ff">new</span> ExpandoObject();</pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum2" style="color: #606060"> 2:</span> command.clipCommand = <span style="color: #0000ff">new</span></pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum3" style="color: #606060"> 3:</span> {</pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum4" style="color: #606060"> 4:</span> <span style="color: #008000">//change state of light 1</span></pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum5" style="color: #606060"> 5:</span> url = <span style="color: #006080">"/api/0/lights/1/state"</span>,</pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum6" style="color: #606060"> 6:</span> method = <span style="color: #006080">"PUT"</span>,</pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum7" style="color: #606060"> 7:</span> body = <span style="color: #0000ff">new</span></pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum8" style="color: #606060"> 8:</span> {</pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum9" style="color: #606060"> 9:</span> <span style="color: #008000">//set the light state changes</span></pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum10" style="color: #606060"> 10:</span> on = <span style="color: #0000ff">true</span></pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum11" style="color: #606060"> 11:</span> }</pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum12" style="color: #606060"> 12:</span> };</pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum13" style="color: #606060"> 13:</span> </pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum14" style="color: #606060"> 14:</span> SendMessage(command).Wait();</pre><!--CRLF--></div></div>
<p>Lines 1-12 builds the clipCommand.<br>Line 14: sends the command</p>
<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; border-top: silver 1px solid; font-family: 'Courier New', courier, monospace; border-right: silver 1px solid; width: 97.5%; border-bottom: silver 1px solid; padding-bottom: 4px; direction: ltr; text-align: left; padding-top: 4px; padding-left: 4px; margin: 20px 0px 10px; border-left: silver 1px solid; line-height: 12pt; padding-right: 4px; max-height: 200px; background-color: #f4f4f4">
<div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum1" style="color: #606060"> 1:</span> <span style="color: #0000ff">private</span> <span style="color: #0000ff">static</span> async Task SendMessage(dynamic command)</pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum2" style="color: #606060"> 2:</span> {</pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum3" style="color: #606060"> 3:</span> <span style="color: #0000ff">string</span> jsonMessage = JsonConvert.SerializeObject(command);</pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum4" style="color: #606060"> 4:</span> </pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum5" style="color: #606060"> 5:</span> HttpClient client = <span style="color: #0000ff">new</span> HttpClient(); </pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum6" style="color: #606060"> 6:</span> HttpContent content = <span style="color: #0000ff">new</span> StringContent(<span style="color: #006080">"clipmessage="</span> + jsonMessage, Encoding.UTF8, <span style="color: #006080">"application/x-www-form-urlencoded"</span>);</pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum7" style="color: #606060"> 7:</span> </pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum8" style="color: #606060"> 8:</span> Uri remoteMessageUrl = <span style="color: #0000ff">new</span> Uri(<span style="color: #006080">"https://www.meethue.com/api/sendmessage?token=<YOUR ACCESS TOKEN>"</span>);</pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum9" style="color: #606060"> 9:</span> var result = await client.PostAsync(remoteMessageUrl, content).ConfigureAwait(<span style="color: #0000ff">false</span>);</pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4"><span id="lnum10" style="color: #606060"> 10:</span> var jsonResult = await result.Content.ReadAsStringAsync().ConfigureAwait(<span style="color: #0000ff">false</span>); </pre><!--CRLF--><pre style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: white"><span id="lnum11" style="color: #606060"> 11:</span> }</pre><!--CRLF--></div></div>
<p>Line 3: creates JSON formatted string of the command.<br>line 6: creates the body of the message, including the encoding and mediatype<br>line 8: creates URI including the access token<br>Line 9: sends request to Hue Portal<br>line 10: will contain results of the request.<br>Possible results could be:<br>success: "{\"code\":200,\"message\":\"ok\",\"result\":\"ok\"}"<br>failure: "{\"code\":109,\"message\":\"I don\\u0027t know that token.\",\"result\":\"error\"}"<br>failure: "{\"code\":113,\"message\":\"Invalid JSON.\",\"result\":\"error\"}"
<p> <h4>Show me the Code</h4>
<p>Get the C# sample from <a href="https://github.com/koenvanderlinden/RemoteHueDemo">https://github.com/koenvanderlinden/RemoteHueDemo</a> that contains sample for sending a message to change lights and how to retrieve bridge status.<br>Let me know if you think this blog post helped you in building a Hue enable application ;-). </p>
<p>TODO: getting the access token is still done by hand and it reuses another popular Hue application. Next step will be how to make the Hue Portal trust your own third party Hue app so you can use your own access token.</p> Koen van der Lindenhttp://www.blogger.com/profile/09745561653129473651noreply@blogger.com1tag:blogger.com,1999:blog-4463898250776378608.post-38379253784234616122014-02-05T20:19:00.000+01:002014-02-05T20:44:05.065+01:00SharePoint issue “The context has expired and can no longer be used. Exception from HRESULT 0x80090317”<p><strong>Problem<br></strong>A client had problems with some workflow instances. Most instances did complete without a problem others failed. Especially workflow that continued after a few days reported the following error in the workflow history log: <br>“{Microsoft.SharePoint.SPException: The context has expired and can no longer be used. (Exception from HRESULT: 0x80090317) ---> System.Runtime.InteropServices.COMException (0x80090317): The context has expired and can no longer be used. (Exception from HRESULT: 0x80090317)<br> at Microsoft.SharePoint.Library.SPRequestInternalClass.SetHttpParameters(String bstrHttpMethod, String “</p> <p>I did some <a href="http://www.urbandictionary.com/define.php?term=googling">googling</a> and found some hits that found a solution in synchronizing the date/time of the WFE’s and admin servers. In our case that wasn’t the the case.</p> <p><strong>Cause<br></strong>After digging into the problem I noticed particular workflow activity opened a site collection using an SPUserToken. <br>using (SPSite site = new SPSite(WorkflowProperties.SiteId, InitializationData.UserToken))<br>{<br>//do some work<br>}<br>The SPUserToken was part of the workflow context and was populated when the workflow instance was first created. Default the SPUserToken is <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spwebservice.tokentimeout.aspx">valid for 1440 minutes (1 day)</a>. In case the workflow instance is de-hydrated after more than 1 day the SPUserToken is expired and isn’t valid anymore. You will get the message “The context has expired and can no longer be used. (Exception from HRESULT: 0x80090317” and are not allowed to open the sitecollection.</p> <p><strong>Conclusion</strong><br>So when you get this specific error make sure to check if you use an old SPUserToken! And be aware the the SPUserToken can expire.</p> <p><strong>Detailed exception information<br></strong>Full error message: "The context has expired and can no longer be used. (Exception from HRESULT: 0x80090317)"<br>Sample Stacktrace:<br>{Microsoft.SharePoint.SPException: The context has expired and can no longer be used. (Exception from HRESULT: 0x80090317) ---> System.Runtime.InteropServices.COMException (0x80090317): The context has expired and can no longer be used. (Exception from HRESULT: 0x80090317)<br> at Microsoft.SharePoint.Library.SPRequestInternalClass.SetHttpParameters(String bstrHttpMethod, String bstrRequestDigest, UInt32 flags, Guid gTranLockerId, Byte[]& ppsaImpersonateUserToken, Boolean bIgnoreTimeout, String bstrUserLogin, String bstrUserKey, UInt32 ulRoleCount, String bstrRoles, Boolean bWindowsMode, ApplicationPrincipalInfo& pAppUserInfo, Boolean bInvalidateCachedConfigurationProperties, Int32 lAppDomainId, ISPManagedObjectFactory pFactory, Boolean bCallstack)<br> at Microsoft.SharePoint.Library.SPRequest.SetHttpParameters(String bstrHttpMethod, String bstrRequestDigest, UInt32 flags, Guid gTranLockerId, Byte[]& ppsaImpersonateUserToken, Boolean bIgnoreTimeout, String bstrUserLogin, String bstrUserKey, UInt32 ulRoleCount, String bstrRoles, Boolean bWindowsMode, ApplicationPrincipalInfo& pAppUserInfo, Boolean bInvalidateCachedConfigurationProperties, Int32 lAppDomainId, ISPManagedObjectFactory pFactory, Boolean bCallstack)<br> --- End of inner exception stack trace ---<br> at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx)<br> at Microsoft.SharePoint.Library.SPRequest.SetHttpParameters(String bstrHttpMethod, String bstrRequestDigest, UInt32 flags, Guid gTranLockerId, Byte[]& ppsaImpersonateUserToken, Boolean bIgnoreTimeout, String bstrUserLogin, String bstrUserKey, UInt32 ulRoleCount, String bstrRoles, Boolean bWindowsMode, ApplicationPrincipalInfo& pAppUserInfo, Boolean bInvalidateCachedConfigurationProperties, Int32 lAppDomainId, ISPManagedObjectFactory pFactory, Boolean bCallstack)<br> at Microsoft.SharePoint.SPGlobal.CreateSPRequestAndSetIdentity(SPSite site, String name, Boolean bNotGlobalAdminCode, String strUrl, Boolean bNotAddToContext, Byte[] UserToken, String userName, Boolean bIgnoreTokenTimeout, Boolean bAsAnonymous)<br> at Microsoft.SharePoint.SPWeb.InitializeSPRequest()<br> at Microsoft.SharePoint.SPWeb.InitWebPublic()<br> at Microsoft.SharePoint.SPWeb.get_CurrentUser()</p> Koen van der Lindenhttp://www.blogger.com/profile/09745561653129473651noreply@blogger.com2tag:blogger.com,1999:blog-4463898250776378608.post-13844879014746480452014-01-30T20:10:00.000+01:002014-02-03T07:04:03.933+01:00How to handle ‘multicultural’ issues with the formula of a SharePoint SPFieldCalculated<p>Setting a <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfieldcalculated.formula.aspx">formula</a> in code for a SharePoint <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfieldcalculated.aspx">SPFieldCalculated</a> is a real nasty task. I spent a lot of time figuring out why some formula’s did work and others did not in various cases.</p> <p>When designing a <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfieldcalculated.formula.aspx">formula</a> you may think you need to take a few things into account like language and separator. During testing I came to the conclusion that the following has impact:<br>- thread culture<br>- separator character used for separating parameters in the formula<br>- SPContext.Current == null or not<br>- SharePoint default language (what language was the original SharePoint setup)<br>- and that the language of the formula method (like CONCATENATE) is not important at all.<br><br><strong>Simple Test Case<br></strong>First let me tell you about my test case I used. Two text fields, one is a company tag, the other is the first name of a contact person. A third will be the calculated field. It will need to show the following: ‘<Company Tag> - <First Name>’, without the ‘.<br>SPFieldText internalName: companyTag, DisplayName (English) = “Company Tag”, DisplayName (Dutch) = “Tag bedrijf”<br>SPFieldText internalName: contactFirstName, DisplayName (English) = “First Name”, DisplayName (Dutch) = “Voornaam”, <br>The creation of the calculated field should be in code (in this case a feature receiver). The deployment should work in various cases like:<br><strong>Case 1: Activating feature by hand in UI.<br>Case 2: Feature is activated by onet.xml of a web template.<br></strong><br><strong>The problem:<br></strong>The problem arises when you need it to work for case 1 and case 2 in different cultures. In my case in English and Dutch. By testing the creation using the following scenario’s you will see where it fails.</p> <p><strong>Scenario 1: Case 1 in English thread culture</strong><br>Formula: “=CONCATENATE([Company Tag],\” – \”,[First Name])”<br>Separator: , (English)<br>Display names: all English<br>Result: <strong>It works…</strong></p> <p><strong>Scenario 2: Case 1 in Dutch thread culture</strong><br>Formula: “=CONCATENATE([Tag bedrijf];\” – \”;[Voornaam])”<br>Separator: ; (Dutch)<br>Display names: all Dutch<br>Result: <strong>It works…</strong></p> <p><strong>Scenario 3: Case 2 in English thread culture<br></strong>Same as Scenario 1:<br>Result: <strong>It works…</strong></p> <p><strong>Scenario 4: Case 2 in Dutch thread culture<br></strong>Same as Scenario 2:<br>Result: <strong>It does NOT work.</strong> </p> <p>Why doesn’t scenario 4 work? Threads are all Dutch, passing all the same parameters for the formula as scenario 2. So why…?<br>Also tried various combinations on the formula like:<br>- English display names, English and Dutch separator,<br>- Using Internal names, English and Dutch separator, <br>- Using Dutch formula method names like “=TEKST.SAMENVOEGEN([Tag bedrijf];\” – \”;[Voornaam])”<br><br>Only thing that seems to work was setting the separator to the default English (the default SharePoint installation culture) variant:<br>Formula: “=CONCATENATE([Tag bedrijf];\” – \”;[Voornaam])”<br><strong>Separator: , (English)</strong><br>Display names: all Dutch</p> <p>The main difference I detected between case 1 and case 2 was the SPContext.Current was null in case 2.<br>In case you design a formula and need to determine the separator, do not only check the Thread culture, but also the existence of SPContext.Current.<br><br><strong>Guidelines regarding formula</strong><br>Adding all variations of testing and failures together I came up with the following guideline when designing the formula for the SPFieldCalculated.<br>- Formula string should start with a '=' (not shown in above cases)<br>- always encapsulate the display name with brackets [], better safe than sorry (not shown in above cases)<br>- in case SPContext.Current is <strong>NOT </strong>null<br>* use field display names for the Thread.CurrentThread.CurrentUICulture <br>* use separator for the Thread.CurrentThread.CurrentUICulture (Dutch= ‘;’ English=”,”)<br>- in case SPContext.Current==null (e.g.: when feature code via activated by an onet.xml of a webtemplate)<br>* use field display names for the Thread.CurrentThread.CurrentUICulture <br>* use separator that matched the SharePoint Initial Installation Language (English on my development machine. Contact me if you know how to determine this in code!)<br>- Methods names in the formula are culture independent, you can use English/Dutch/Whatever without a problem. (e.g. CONCATENATE and TEKST.SAMENVOEGEN work in English and Dutch thread culture)<br><br>I hope I saved you some valuable time in creating formula’s for <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfieldcalculated.aspx">SPFieldCalculated</a> fields in code.<br>New insights on the formula are welcome.</p> Koen van der Lindenhttp://www.blogger.com/profile/09745561653129473651noreply@blogger.com1tag:blogger.com,1999:blog-4463898250776378608.post-56536856610577828252013-09-25T07:34:00.000+02:002013-09-25T08:07:36.228+02:00SharePoint Synchronous Event Receiver with message to UI and saving form data<p>The goal is to save data from the new/edit form to list item and in certain situations show a message to UI by using event receivers.</p> <p>As we all know showing a message to UI is not going to work when using async event receivers. So we’re stuck to use sync event receivers. At first you will see examples that shows a message by using code like this:</p> <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"> <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">try</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #008000">//some code</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">}</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">catch</span> (Exception ex)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> properties.Status = SPEventReceiverStatus.CancelWithError;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> properties.ErrorMessage = ex.Message;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> properties.Cancel = <span style="color: #0000ff">true</span>;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">}</pre><!--CRLF--></div></div>
<p>The options for properties.<a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.speventpropertiesbase.status.aspx">Status</a> are:<br><a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.speventreceiverstatus.aspx">Continue</a>, there is no error.<br><a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.speventreceiverstatus.aspx">CancelNoError</a>, silently cancel the request as if the request has succeeded.<br><a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.speventreceiverstatus.aspx">CancelWithError</a>, cancel the request with the error message specified in <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.speventpropertiesbase.errormessage.aspx">ErrorMessage</a>.<br><a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.speventreceiverstatus.aspx">CancelWithRedirectUrl</a> cancel the request and redirect to the URL specified in <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.speventpropertiesbase.redirecturl.aspx">RedirectUrl</a>.</p>
<p>The only usable is <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.speventreceiverstatus.aspx">CancelWithRedirectUrl</a>. However this will <strong>not</strong> save your form data to the listitem. So all changes are lost.<br>Where is the option to ‘ContinueWithRedirectUrl’? It doesn’t exist.<br>Luckily we have the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.utilities.sputility%28v=office.14%29.aspx">SPUtility</a> class with the <a href="http://msdn.microsoft.com/en-us/library/ms463664%28v=office.14%29.aspx">Redirect</a> method. When using the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.utilities.spredirectflags%28v=office.14%29.aspx">SPRedirectFlag.DoNotEndResponse</a> flag it will <strong>not </strong>abort the event receiver thread (Flag Default will abort event receiver thread and therefor will not save the afterproperties on the list item.). In this case the event receiver thread will be completed and afterproperties are save to the list item. And the redirect will be processed. You could redirect a user to a custom page, provide some parameters and show a message as you like.</p>
<p>Code sample of the redirect:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">SPUtility.Redirect(<span style="color: #006080">"notificationpage.aspx?status=somestatusvalue"</span>, SPRedirectFlags.DoNotEndResponse, HttpContext.Current);</pre><!--CRLF--></div></div> Koen van der Lindenhttp://www.blogger.com/profile/09745561653129473651noreply@blogger.com0tag:blogger.com,1999:blog-4463898250776378608.post-60187407113902540532013-06-12T09:32:00.000+02:002013-06-12T09:56:37.485+02:00Copy SPField property values without changing Content Type<p>In a particular project for a client I needed to copy all field properties from document A to document B. However the content type should not be changed. For simplicity I ignore edge cases. For example in case the source and destination content type have different required SPFields.</p> <p>At first I copied all available fields from source to destination:<br> <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"> <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">foreach</span> (SPField field <span style="color: #0000ff">in</span> sourceItem.Fields)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">if</span> (field.ReadOnlyField)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">continue</span>;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">if</span> (destinationListitem.Fields.ContainsField(field.InternalName))</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> destinationListitem[field.InternalName] = sourceItem[field.InternalName];</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">}</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">destinationListitem.SystemUpdate()</pre><!--CRLF--></div></div></p>
<p>The content type changed. No wonder as the SPField ‘ContentType’ was copied.<br>Changed code to to ignore SPField ‘ContentType’</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">IEnumerable<<span style="color: #0000ff">string</span>> ignoreFields = <span style="color: #0000ff">new</span> List<<span style="color: #0000ff">string</span>>()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #006080">"ContentType"</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">};</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">foreach</span> (SPField field <span style="color: #0000ff">in</span> sourceItem.Fields)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">if</span> (field.ReadOnlyField)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">continue</span>;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">if</span> (ignoreFields.Contains(field.InternalName, StringComparer.InvariantCultureIgnoreCase))</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">continue</span>;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">if</span> (destinationListitem.Fields.ContainsField(field.InternalName))</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> destinationListitem[field.InternalName] = sourceItem[field.InternalName];</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">}</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">destinationListitem.SystemUpdate()</pre><!--CRLF--></div></div>
<p>But still content type changed.<br>It turns out that you need to skip the SPField ‘ContentType’ and ‘MetaInfo’ to make sure the content type of the destination item is not changed.</p>
<p>Final code snippet:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">IEnumerable<<span style="color: #0000ff">string</span>> ignoreFields = <span style="color: #0000ff">new</span> List<<span style="color: #0000ff">string</span>>()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #006080">"ContentType"</span>,</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #006080">"MetaInfo"</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">};</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">foreach</span> (SPField field <span style="color: #0000ff">in</span> sourceItem.Fields)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">{</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">if</span> (field.ReadOnlyField)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">continue</span>;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">if</span> (ignoreFields.Contains(field.InternalName, StringComparer.InvariantCultureIgnoreCase))</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">continue</span>;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> <span style="color: #0000ff">if</span> (destinationListitem.Fields.ContainsField(field.InternalName))</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> destinationListitem[field.InternalName] = sourceItem[field.InternalName];</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">}</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">destinationListitem.SystemUpdate()</pre><!--CRLF--></div></div> Koen van der Lindenhttp://www.blogger.com/profile/09745561653129473651noreply@blogger.com0tag:blogger.com,1999:blog-4463898250776378608.post-34506657209194793112012-10-14T11:55:00.000+02:002012-10-14T11:55:38.865+02:00Mapping DateTime properties in SharePoint User Profile using BCS<p>Just a quick one this time.</p> <p>When importing a field to a SharePoint UserProfile DateTime type in the User Profile. You normaly have a BCS model with a property of System.DateTime and map that to the UserProfile. However this won't work, you will get errors like this: <br />"Microsoft.Office.Server.UserProfiles.PropertyInvalidFormatException: Invalid Date Format: Input must match smalldatetime data type, or be a string that parses to match the Guid data type ---> System.FormatException: String was not recognized as a valid DateTime.    <br /> at System.DateTimeParse.ParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style)    <br /> at Microsoft.Office.Server.UserProfiles.UserProfileGlobal.ValidatedDate(Object value, PropertyDataType propDataType, SiteContext si)     - <br /> -- End of inner exception stack trace ---    <br /> at Microsoft.Office.Server.UserProfiles.UserProfileGlobal.ValidatedDate(Object value, PropertyDataType propDataType, SiteContext si)    <br /> at Microsoft.Office.Server.UserProfiles.UserProfileGlobal.ValidatedSingleValue(Object value, ProfileSubtypeProperty prop, PropertyDataType </p> <p>propDataType, UserFormat userFormat, UserProfileApplicationProxy userProfileApplicationProxy, Guid partitionID, SiteContext si)    <br /> at Microsoft.Office.Server.UserProfiles.UserProfile.BulkPropertiesUpdate(Int64 importExportId, Hashtable properties, String strAccountName)."</p> <p>To fix you need to do the following:</p> <p>- The property in your BCS model should still be 'System.DateTime'. Otherwise you cannot map the BCS to the UserProfile Date typed property. <br />- However make sure your BCS code outputs a string in the following format: yyyyMMddHHmmss.0Z (like: .ToString("yyyyMMddHHmmss.0Z", CultureInfo.InvariantCulture); <br />This will make sure the output can be converted to a DateTime.</p> <p>If you want more details use reflector on: <br />- class Microsoft.Office.Server.UserProfiles.UserProfileGlobal <br />- method private static DateTime ValidatedDate(object value, PropertyDataType propDataType, SiteContext si)</p> Koen van der Lindenhttp://www.blogger.com/profile/09745561653129473651noreply@blogger.com3tag:blogger.com,1999:blog-4463898250776378608.post-77536607098316819942012-04-24T10:18:00.001+02:002012-04-29T08:11:25.801+02:00How to add a Windows account to Security Group in a claims based SharePoint 2010 environment<p>In a timer job I added users to a certain SPGroup and added this group to some libraries with contribute rights. When I logged is with that user account it didn’t have the contribute rights. The problem was that the Windows account was added instead of the claims based user.</p> <p>At first I just used the following code:</p> <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"> <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1"> 1:</span> String loginName = <span style="color: #006080">"SP2010\user1"</span>;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2"> 2:</span> SPGroup group = web.SiteGroups[<span style="color: #006080">"somegroup"</span>];</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3"> 3:</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4"> 4:</span> SPUser user = web.EnsureUser(loginName);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5"> 5:</span> <span style="color: #0000ff">if</span> (user != <span style="color: #0000ff">null</span>)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6"> 6:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7"> 7:</span> group.AddUser(user);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8"> 8:</span> }</pre><!--CRLF--></div></div>
<p>However this added a user as formatted in this XML:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><User ID=<span style="color: #006080">"442"</span> Sid=<span style="color: #006080">"S-1-5-21-4190988674-4107964418-2216591577-1137"</span> Name=<span style="color: #006080">"Some name"</span> LoginName=<span style="color: #006080">"SP2010\user1"</span> Email=<span style="color: #006080">"test@test.com"</span> Notes=<span style="color: #006080">""</span> IsSiteAdmin=<span style="color: #006080">"False"</span> IsDomainGroup=<span style="color: #006080">"False"</span> Flags=<span style="color: #006080">"0"</span> /></pre><br></div><pre class="csharpcode">I changed it to look for the correct SPUser using this code snippet:</pre>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1"> 1:</span> <span style="color: #0000ff">String</span> loginName = <span style="color: #006080">"SP2010\user1"</span>;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2"> 2:</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3"> 3:</span> SPClaimProviderManager mgr = SPClaimProviderManager.Local;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4"> 4:</span> <span style="color: #0000ff">if</span> (mgr != null)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5"> 5:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6"> 6:</span> SPClaim claim = <span style="color: #0000ff">new</span> SPClaim(SPClaimTypes.UserLogonName, loginName, <span style="color: #006080">"http://www.w3.org/2001/XMLSchema#string"</span>, SPOriginalIssuers.Format(SPOriginalIssuerType.Windows));</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7"> 7:</span> claimLoginName = mgr.EncodeClaim(claim);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8"> 8:</span> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9"> 9:</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10"> 10:</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11"> 11:</span> SPGroup group = web.SiteGroups[<span style="color: #006080">"somegroup"</span>];</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum12"> 12:</span> SPUser user = web.EnsureUser(claimLoginName);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum13"> 13:</span> <span style="color: #0000ff">if</span> (user != null)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum14"> 14:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum15"> 15:</span> group.AddUser(user);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum16"> 16:</span> }</pre><!--CRLF--></div></div>
<style type="text/css">.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p>This will generate a claim that represents the windows account “SP2010\user1”. This will find the correct SPUser, the XML is:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><User ID=<span style="color: #006080">"255"</span> Sid=<span style="color: #006080">""</span> Name=<span style="color: #006080">"Some name"</span> LoginName=<span style="color: #006080">"i:0#.w|SP2010\user1"</span> Email=<span style="color: #006080">"test@test.com"</span> Notes=<span style="color: #006080">""</span> IsSiteAdmin=<span style="color: #006080">"False"</span> IsDomainGroup=<span style="color: #006080">"False"</span> Flags=<span style="color: #006080">"0"</span> /></pre><br></div>
<p>Notice the formatting of the LoginName.</p>
<p>Now the correct user account (in claims format) is added to the library with contribute rights the user logging in with SP2010\user1 can contribute.</p> Koen van der Lindenhttp://www.blogger.com/profile/09745561653129473651noreply@blogger.com0tag:blogger.com,1999:blog-4463898250776378608.post-23826148707092093472012-04-16T09:41:00.001+02:002012-04-16T09:41:56.622+02:00Remote Hyper-V Management from client in different Domain<p>Recently the employees of Yellow & Red migrated the laptops to another domain. However the Hyper-V was left as-is and still run in the Yellow & Red domain. The problem is that you cannot manage the Hyper-V using the standard Hyper-V Remote Manager as you are not in the same domain.</p> <p>You need to configure a lot of stuff. Thanks to <a href="http://blogs.technet.com/b/jhoward/">John Howard</a> we just need to run a few scripts.</p> <p>Follow these steps:</p> <p>Download: <a href="http://archive.msdn.microsoft.com/HVRemote/Release/">HVRemote.wsf</a> from the <a href="http://archive.msdn.microsoft.com/HVRemote">Hyper-V Remote Management Configuration Utility</a></p> <p>On Hyper-V server execute the following commands:</p> <p>cscript hvremote.wsf /add:domain\user</p> <p>On Client: (in elevated mode)</p> <p>cscript hvremote.wsf /mmc:enable</p> <p>cscript hvremote.wsf /anondcom:grant</p> <p>Important note for the next steps:<br>ServerComputerName should be the name as shown in Hyper-V server, run “sconfig.cmd” and see “Computer name” at number 2. Otherwise you’ll get issues trying to query the root\cimv2 WMI namespace).</p> <p>Add credentials to your credential store:<br>cmdkey /add:ServerComputerName /user:ServerComputerName\UserName /pass</p> <p>- add a line to hosts file. In my case I cannot resolve ServerComputerName.<br><br>192.1.3.4 ServerComputerName</p> <p>To test the communication run this line on the client:</p> <p>cscript hvremote.wsf /show /target:ServerComputerName </p> <p>You should now be able to connect to your Hyper-V server.</p> Koen van der Lindenhttp://www.blogger.com/profile/09745561653129473651noreply@blogger.com3tag:blogger.com,1999:blog-4463898250776378608.post-56608644817488807652011-11-15T13:04:00.001+01:002011-11-15T13:04:32.495+01:00How to add a survey list to the Quicklaunch<p>When you add a survey list to a site using a webtemplate or sitetemplate you add the following line to the onet.xml:</p> <div id="codeSnippetWrapper"> <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff"><</span><span style="color: #800000">Lists</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">List</span> <span style="color: #ff0000">FeatureId</span><span style="color: #0000ff">="00bfea71-eb8a-40b1-80c7-506be7590102"</span> <span style="color: #ff0000">Type</span><span style="color: #0000ff">="102"</span> <span style="color: #ff0000">Title</span><span style="color: #0000ff">="$Resources:core,surveyList;"</span> <span style="color: #ff0000">Url</span><span style="color: #0000ff">="$Resources:core,lists_Folder;/$Resources:core,surveyList;"</span> <span style="color: #ff0000">QuickLaunchUrl</span><span style="color: #0000ff">="$Resources:core,lists_Folder;/$Resources:core,surveyList;/overview.aspx"</span> <span style="color: #0000ff">/></span><br /><span style="color: #0000ff"></</span><span style="color: #800000">Lists</span><span style="color: #0000ff">></span></pre>
<br /></div>
<p>When you create a site with this onet.xml the survey list is created however it’s not added to the quicklaunch. This is probably because the <Navbars> doesn’t contain a ‘Survey’ category.</p>
<p>To fix this add this line to the <Navbars> element:</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff"><</span><span style="color: #800000">NavBar</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="$Resources:core,category_Surveys;"</span> <span style="color: #ff0000">Prefix</span><span style="color: #0000ff">="&lt;table border='0' cellpadding='4' cellspacing='0'&gt;"</span> <span style="color: #ff0000">Body</span><span style="color: #0000ff">="&lt;tr&gt;&lt;td&gt;&lt;table border='0' cellpadding='0' cellspacing='0'&gt;&lt;tr&gt;&lt;td&gt;&lt;img src='/_layouts/images/blank.gif' id='100' alt='' border='0'&gt;&amp;nbsp;&lt;/td&gt;&lt;td valign='top'&gt;&lt;a id='onetleftnavbar#LABEL_ID#' href='#URL#'&gt;#LABEL#&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;"</span> <span style="color: #ff0000">Suffix</span><span style="color: #0000ff">="&lt;/table&gt;"</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="1007"</span> <span style="color: #0000ff">/></span></pre>
<br /></div>
<p>Or you could use one of the alternatives:
<br />- Add the survey list in code (web.Lists.Add with SPListTemplateType.Survey) and set OnQuickLaunch to true.
<br />- manually add the survey list to the quicklaunch using the List Settings –> Title, description and navigation. The Navbar item will be added automatically.</p> Koen van der Lindenhttp://www.blogger.com/profile/09745561653129473651noreply@blogger.com1tag:blogger.com,1999:blog-4463898250776378608.post-1666485932970988922011-10-19T09:16:00.001+02:002011-10-19T09:29:08.969+02:00Deploy files to Pages subfolder (SharePoint 2010)<p> <br /><strong>Scenario: <br /></strong>Deploy pages/files to a subfolder in the pages library.</p> <p><strong>How it’s done: <br /></strong>In Visual Studio 2010 create a module:</p> <p><a href="http://lh6.ggpht.com/-9QS3369HkEc/Tp55NTJmggI/AAAAAAAAAKg/6GrwEaWrw80/s1600-h/image%25255B5%25255D.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-2C7sXp507fc/Tp55NyXoZ9I/AAAAAAAAAKo/joJV0uObbjk/image_thumb%25255B1%25255D.png?imgmax=800" width="183" height="69" /></a></p> <p>with the following elements.xml</p> <div id="codeSnippetWrapper"> <div> <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff"><?</span><span style="color: #800000">xml</span> <span style="color: #ff0000">version</span><span style="color: #0000ff">="1.0"</span> <span style="color: #ff0000">encoding</span><span style="color: #0000ff">="utf-8"</span>?<span style="color: #0000ff">></span><br /><span style="color: #0000ff"><</span><span style="color: #800000">Elements</span> <span style="color: #ff0000">xmlns</span><span style="color: #0000ff">="http://schemas.microsoft.com/sharepoint/"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">Module</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="AdminPages"</span> <span style="color: #ff0000">Url</span><span style="color: #0000ff">="$Resources:osrvcore,List_Pages_UrlName;/AdminPages"</span> <span style="color: #ff0000">Path</span><span style="color: #0000ff">="AdminPages"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">File</span> <span style="color: #ff0000">Path</span><span style="color: #0000ff">="ChangePassword.aspx"</span> <span style="color: #ff0000">Url</span><span style="color: #0000ff">="ChangePassword.aspx"</span> <span style="color: #ff0000">Type</span><span style="color: #0000ff">="GhostableInLibrary"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">File</span> <span style="color: #ff0000">Path</span><span style="color: #0000ff">="ForgotPassword.aspx"</span> <span style="color: #ff0000">Url</span><span style="color: #0000ff">="ForgotPassword.aspx"</span> <span style="color: #ff0000">Type</span><span style="color: #0000ff">="GhostableInLibrary"</span> <span style="color: #0000ff">/></span><br /><span style="color: #0000ff"></</span><span style="color: #800000">Module</span><span style="color: #0000ff">></span><br /><span style="color: #0000ff"></</span><span style="color: #800000">Elements</span><span style="color: #0000ff">></span></pre>
</div>
<div>
<br />Some explanation about the elements file:</div>
<div>Module.Name: name of the module</div>
<div>Module.Url: location in SharePoint, where do you want to deploy the files to.</div>
<div>Module.Path: location of the files in your feature (In this case in VS2010 the ‘AdminPages’ module creates a directory in the feature with name ‘AdminPages’)</div>
<div>File.Path: location of the file in your feature (it also uses the Module.Path, so don’t add the ‘AdminPages’ because it’s defined in the Module.Path)</div>
<div>File.Url: filename in SharePoint (you could name the file whatever you like)</div>
<div> </div>
<div>Add the module to a feature.
<br />Deploy the solution.</div>
</div>
<p>After installing and activating the feature (that contains the AdminPages module) you will see that a folder ‘AdminPages’ is created in the /Pages (depending on language) folder.</p>
<p><a href="http://lh3.ggpht.com/-XMz2BpZdZwM/Tp55OJOgUtI/AAAAAAAAALQ/dEIg-jah22g/s1600-h/image%25255B15%25255D.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-tF6rj1QIVM4/Tp55OYGOC8I/AAAAAAAAALU/nM-wufQxG2Q/image_thumb%25255B7%25255D.png?imgmax=800" width="237" height="131" /></a></p>
<p><a href="http://lh5.ggpht.com/-tdy6g7GCQ30/Tp55OkQQAiI/AAAAAAAAALY/ab_YHj7-zdo/s1600-h/image%25255B16%25255D.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-XEiI20sRnTQ/Tp55PBWTufI/AAAAAAAAALc/EJkXwzKo4qg/image_thumb%25255B8%25255D.png?imgmax=800" width="236" height="130" /></a></p> Koen van der Lindenhttp://www.blogger.com/profile/09745561653129473651noreply@blogger.com0tag:blogger.com,1999:blog-4463898250776378608.post-68146967411920700342011-06-24T12:33:00.001+02:002011-06-24T12:33:25.265+02:00Reminders for Continuous build for SharePoint projects in Team Foundation Server (TFS)<p>Based on this MSDN article <a href="http://msdn.microsoft.com/en-us/library/ff622991.aspx" target="_blank">How to Build SharePoint Projects with TFS Team Build</a> I setup the build machine. When doing so and tested it on my current SharePoint 2010 project I found some issues. As a reminder-to-self here some notes:</p> <p><strong>Deployment of DLLs to GAC</strong></p> <p>Some dll’s should be deployed to GAC. Use gacutil (of the .NET 4 framework) to do this, using a .NET 2 or 3.5 version doesn’t work. </p> <p>- Download and install the <a href="http://www.microsoft.com/downloads/dlx/en-us/listdetailsview.aspx?FamilyID=6b6c21d2-2006-4afa-9702-529fa782d63b" target="_blank">Microsoft Windows SDK for Windows 7 and .NET Framework 4</a> <br />- Gacutil location for 64bit systems is C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\NETFX 4.0 Tools\</p> <p><strong>SharePoint DLLs</strong></p> <p><strong></strong>Copy all SharePoint dll’s from the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\ <br />When your SharePoint project references Microsoft.SharePoint.Publishing, also copy System.Web.DataVisualization.dll (.NET 3.5). It location is C:\Program Files (x86)\Microsoft Chart Controls\Assemblies\ This is because the publishing assembly references the DataVisualization assembly.</p> <p><strong>Updating SharePoint 2010</strong></p> <p>When installing cumulative or Service Packs on SharePoint 2010, you need to update the dll’s on your build server to keep them aligned.</p> Koen van der Lindenhttp://www.blogger.com/profile/09745561653129473651noreply@blogger.com0tag:blogger.com,1999:blog-4463898250776378608.post-64628856921390295702011-06-23T16:08:00.001+02:002011-06-23T16:08:04.887+02:00SharePoint 2010 Workflow: Could not load file or assembly '$assemblyname$'<p>During workflow development I got the following error when starting a Site workflow:</p> <div id="codeSnippetWrapper"> <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><p>Load Workflow Assembly: System.IO.FileNotFoundException:<br />Could not load file or assembly '$assemblyname$' or one of its dependencies. The system cannot find the file specified. File name: '$assemblyname$'</p></pre>
<br /></div>
<p>Very strange, it did worked for months. So I checked the workflow feature in the 14-hive. The element manifest was wrong. It contained the $assemblyname$ tag instead of the assembly name.</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff"><</span><span style="color: #800000">Workflow</span><br /> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="Ctalk - MailCtalkEditieWF"</span><br /> <span style="color: #ff0000">Description</span><span style="color: #0000ff">="Workflow for sending Ctalk Editions"</span><br /> <span style="color: #ff0000">Id</span><span style="color: #0000ff">="15f3ae38-12bc-4dbf-ad2b-9281ff09d43e"</span><br /> <span style="color: #ff0000">CodeBesideClass</span><span style="color: #0000ff">="Ctac.Ctalk.MailCtalkEditie.MailCtalkEditie"</span><br /> <span style="color: #ff0000">CodeBesideAssembly</span><span style="color: #0000ff">="$assemblyname$"</span><span style="color: #0000ff">></span></pre>
<br /></div>
<p>After a ‘normal’ deployment in VS2010 the element manifest file was correct:</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><p><span style="color: #0000ff"><</span><span style="color: #800000">Workflow</span><br /> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="Ctalk - MailCtalkEditieWF"</span><br /> <span style="color: #ff0000">Description</span><span style="color: #0000ff">="Workflow for sending Ctalk Editions"</span><br /> <span style="color: #ff0000">Id</span><span style="color: #0000ff">="15f3ae38-12bc-4dbf-ad2b-9281ff09d43e"</span><br /> <span style="color: #ff0000">CodeBesideClass</span><span style="color: #0000ff">="Ctac.Ctalk.MailCtalkEditie.MailCtalkEditie"</span><br /> <span style="color: #ff0000">CodeBesideAssembly</span><span style="color: #0000ff">="Ctac.Ctalk, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6a509658686505f0"</span><span style="color: #0000ff">></span></p></pre>
<br /></div>
<p>So what was the problem… It’s the VS2010 ‘Copy to SharePoint Root’ command part of the <a href="http://cksdev.codeplex.com/" target="_blank">CKSDev extension</a>. It just copied the file as is, it doesn’t replace the tag. So keep this in mind when using the ‘Copy to SharePoint Root’ command in combination with workflow development.</p> Koen van der Lindenhttp://www.blogger.com/profile/09745561653129473651noreply@blogger.com4tag:blogger.com,1999:blog-4463898250776378608.post-40342775778153852772011-06-22T12:25:00.001+02:002011-06-22T12:25:22.556+02:00Provisioning URL values with description using element manifest<p>When provisioning files/items that contain an URL typed field you probably want to provide an url and description. When using an element manifest to provision some content you probably use something like this:</p> <div id="codeSnippetWrapper"> <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff"><?</span><span style="color: #800000">xml</span> <span style="color: #ff0000">version</span><span style="color: #0000ff">="1.0"</span> <span style="color: #ff0000">encoding</span><span style="color: #0000ff">="utf-8"</span>?<span style="color: #0000ff">></span><br /><span style="color: #0000ff"><</span><span style="color: #800000">Elements</span> <span style="color: #ff0000">xmlns</span><span style="color: #0000ff">="http://schemas.microsoft.com/sharepoint/"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">Module</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="Banners"</span> <span style="color: #ff0000">Url</span><span style="color: #0000ff">="Banners"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">File</span> <span style="color: #ff0000">Path</span><span style="color: #0000ff">="Banners\banner1.png"</span> <span style="color: #ff0000">Url</span><span style="color: #0000ff">="banner1.png"</span> <span style="color: #ff0000">Type</span><span style="color: #0000ff">="GhostableInLibrary"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">Property</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="URL"</span> <span style="color: #ff0000">Type</span><span style="color: #0000ff">="string"</span> <span style="color: #ff0000">Value</span><span style="color: #0000ff">="http://www.yellowred.nl"</span><span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">Property</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="NewWindow"</span> <span style="color: #ff0000">Value</span><span style="color: #0000ff">="true"</span><span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">File</span><span style="color: #0000ff">></span><br /><span style="color: #0000ff"></</span><span style="color: #800000">Module</span><span style="color: #0000ff">></span><br /><span style="color: #0000ff"></</span><span style="color: #800000">Elements</span><span style="color: #0000ff">></span></pre>
</div>
<div>There’s no room for providing a description. The <a href="http://msdn.microsoft.com/en-us/library/cc264281.aspx" target="_blank">property element</a> has the following ‘Type’ attribute options: int, string, datetime. So no url type.</div>
<p>As you know the <a href="http://msdn.microsoft.com/EN-US/library/ms472498" target="_blank">URL</a> value is just a string with in specific format: <url>, <description>
<br />You can also find this format when using SharePoint Manager 2010. Open the item containing the url field. Check the schema.xml and search for the url.</p>
<p>To provide a description to the url, provision your data like this:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff"><?</span><span style="color: #800000">xml</span> <span style="color: #ff0000">version</span><span style="color: #0000ff">="1.0"</span> <span style="color: #ff0000">encoding</span><span style="color: #0000ff">="utf-8"</span>?<span style="color: #0000ff">></span><br /><span style="color: #0000ff"><</span><span style="color: #800000">Elements</span> <span style="color: #ff0000">xmlns</span><span style="color: #0000ff">="http://schemas.microsoft.com/sharepoint/"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">Module</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="Banners"</span> <span style="color: #ff0000">Url</span><span style="color: #0000ff">="Banners"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">File</span> <span style="color: #ff0000">Path</span><span style="color: #0000ff">="Banners\banner1.png"</span> <span style="color: #ff0000">Url</span><span style="color: #0000ff">="banner1.png"</span> <span style="color: #ff0000">Type</span><span style="color: #0000ff">="GhostableInLibrary"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">Property</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="URL"</span> <span style="color: #ff0000">Type</span><span style="color: #0000ff">="string"</span> <span style="color: #ff0000">Value</span><span style="color: #0000ff">="http://www.yellowred.nl, Yellow and Red"</span><span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">Property</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="NewWindow"</span> <span style="color: #ff0000">Value</span><span style="color: #0000ff">="true"</span><span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">File</span><span style="color: #0000ff">></span><br /><span style="color: #0000ff"></</span><span style="color: #800000">Module</span><span style="color: #0000ff">></span><br /><span style="color: #0000ff"></</span><span style="color: #800000">Elements</span><span style="color: #0000ff">></span></pre>
</div>
</div> Koen van der Lindenhttp://www.blogger.com/profile/09745561653129473651noreply@blogger.com1tag:blogger.com,1999:blog-4463898250776378608.post-35776722124459874842011-06-03T08:42:00.001+02:002011-06-03T08:42:18.029+02:00Issues with RemoveFieldRef and ContentTypes<p>When inheriting from content types you can use <a href="http://msdn.microsoft.com/en-us/library/aa543602.aspx">RemoveFieldRef</a> to remove unused fields. The <a href="http://msdn.microsoft.com/en-us/library/aa543602.aspx">RemoveFieldRef</a> however is very picky when you want it to work. </p> <p>Example content type “SampleInheritance” (inherits from content type: Event (0x0102))</p> <div id="codeSnippetWrapper"> <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><Elements xmlns=<span style="color: #006080">"http://schemas.microsoft.com/sharepoint/"</span>><br /> <ContentType <br /> ID=<span style="color: #006080">"0x0102002748FB863AA69C449E1D30D488B1DFDD"</span><br /> Name=<span style="color: #006080">"SampleInheritance"</span><br /> Description=<span style="color: #006080">"Create a new meeting, deadline or other event."</span><br /> Group=<span style="color: #006080">"Sample"</span><br /> Inherits=<span style="color: #006080">"FALSE"</span><br /> Hidden=<span style="color: #006080">"false"</span><br /> ReadOnly=<span style="color: #006080">"false"</span><br /> Sealed=<span style="color: #006080">"false"</span>><br /> <FieldRefs><br /> <FieldRef ID=<span style="color: #006080">"fce16b4c-fe53-4793-aaab-b4892e736d15"</span> Name=<span style="color: #006080">"EMail"</span> DisplayName=<span style="color: #006080">"E-Mail"</span> /><br /> <FieldRef ID=<span style="color: #006080">"114bf263-2846-4854-839b-715c0f573cea"</span> Name=<span style="color: #006080">"Header1"</span> DisplayName=<span style="color: #006080">"Header"</span> /><br /> <FieldRef ID=<span style="color: #006080">"f9589629-6f74-403e-83f6-8da3316dcca2"</span> Name=<span style="color: #006080">"BedankPagina"</span> DisplayName=<span style="color: #006080">"BedankPagina"</span> /><br /> <RemoveFieldRef ID=<span style="color: #006080">"{7d95d1f4-f5fd-4a70-90cd-b35abc9b5bc8}"</span>/><br /> </FieldRefs><br /> <XmlDocuments xmlns=<span style="color: #006080">"http://schemas.microsoft.com/sharepoint/"</span>><br /> <XmlDocument NamespaceURI=<span style="color: #006080">"http://schemas.microsoft.com/sharepoint/v3/contenttype/forms"</span>><br /> <FormTemplates xmlns=<span style="color: #006080">"http://schemas.microsoft.com/sharepoint/v3/contenttype/forms"</span>><br /> <Display>ListForm</Display><br /> <Edit>ListForm</Edit><br /> <New>ListForm</New><br /> </FormTemplates><br /> </XmlDocument><br /> </XmlDocuments><br /> </ContentType><br /></Elements></pre>
</div>
<p>Follow these rules:</p>
<ol>
<li>in <RemoveFieldRef> the GUID in the ID should start with ‘{‘ and ends with ‘}’ </li>
<li>in <RemoveFieldRef> the GUID in the ID must be lowercase </li>
<li>set "Inherits=false” or remove the attribute. </li>
</ol> Koen van der Lindenhttp://www.blogger.com/profile/09745561653129473651noreply@blogger.com2tag:blogger.com,1999:blog-4463898250776378608.post-55854592496950672542011-02-23T15:43:00.001+01:002011-02-23T15:49:14.794+01:00Programmatically connect two ListViewWebParts to Filter based on value of Provider Web Part<p>When you want to connect two ListViewWebParts on a page using the user interface is easy. However doing it programmatically was a bit more complicated. It’s not complex, but you need to know what classes you need to use.</p> <p><strong>Connecting Web Parts using the User interface:</strong></p> <p><a href="http://lh3.ggpht.com/_DO_9NbckVuk/TWUc-ddEUkI/AAAAAAAAAIo/nhYD8Sfi3pM/s1600-h/image%5B5%5D.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_DO_9NbckVuk/TWUc-25eL9I/AAAAAAAAAIs/PNi3_kYNU3Y/image_thumb%5B10%5D.png?imgmax=800" width="333" height="173" /></a> <br />Select the provider Web Part and connect to the consumer web part with the ‘Send Row of Data To’ option. </p> <p><a href="http://lh3.ggpht.com/_DO_9NbckVuk/TWUc_LKZLKI/AAAAAAAAAIw/mcqP_3noe3w/s1600-h/image%5B13%5D.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_DO_9NbckVuk/TWUc_klo6tI/AAAAAAAAAI0/MsoLntzyoHY/image_thumb%5B14%5D.png?imgmax=800" width="334" height="170" /></a> <br />Step 1: <br />Configure the connection on the Consumer Web Part. <br />Select ‘Get Filter Values From’ <br /> <br /><a href="http://lh5.ggpht.com/_DO_9NbckVuk/TWUc_9XEMUI/AAAAAAAAAI4/q8iVzI3MDVw/s1600-h/image%5B14%5D.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_DO_9NbckVuk/TWUdAG016LI/AAAAAAAAAI8/HbXpZtiZme4/image_thumb%5B15%5D.png?imgmax=800" width="330" height="168" /></a></p> <p>Step 2: <br />Provider Field Name: Title(linked to item) <br />Consumer Field Name: ArticleEditionTitle</p> <p>The provider and consumer field names are dependent on your needs. In this case the value of the Title of the provider Web Part is passed to the consumer web part. The consumer web part will only show rows where ArticleEditionTitle is equal to the passed value.</p> <p> <strong>Connecting Web Parts programmatically: <br /></strong>Use the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webpartpages.sprowtoparameterstransformer.aspx">SPRowToParametersTransformer</a> class, provide the correct provider and consumer fieldnames. These fields are the same as the ones used in step 2 of the user interface procedure.</p> <div id="codeSnippetWrapper"> <div id="codeSnippetWrapper"> <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">SPRowToParametersTransformer transformer = <span style="color: #0000ff">new</span> SPRowToParametersTransformer();<br />transformer.ProviderFieldNames = <span style="color: #0000ff">new</span> <span style="color: #0000ff">string</span>[] { <span style="color: #006080">"LinkTitleNoMenu"</span> };<br />transformer.ConsumerFieldNames = <span style="color: #0000ff">new</span> <span style="color: #0000ff">string</span>[] { <span style="color: #006080">"ArticleEditionTitle"</span> };<br /></pre>
<br /></div>
<div>Get the WebParts that need to get connected</div>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">string</span> providerWebPartTitle = <span style="color: #006080">"Editions"</span>;<br /><span style="color: #0000ff">string</span> consumerWebPartTitle = <span style="color: #006080">"Articles"</span>;<br /><br />WebPart providerPart = (from WebPart w <span style="color: #0000ff">in</span> mgr.WebParts <span style="color: #0000ff">where</span> w.Title == providerWebPartTitle select w).FirstOrDefault();<br />WebPart consumerPart = (from WebPart w <span style="color: #0000ff">in</span> mgr.WebParts <span style="color: #0000ff">where</span> w.Title == consumerWebPartTitle select w).FirstOrDefault();<br /></pre>
<br /></div>
<div>Determine the ConnectionPoints of the webparts. Note the provider/consumer ConnectionIds</div>
</div>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">string</span> providerConnectionId = <span style="color: #006080">"DFWP Row Provider ID"</span>;<br /><span style="color: #0000ff">string</span> consumerConnectionId = <span style="color: #006080">"DFWP Filter Consumer ID"</span>;<br /><br /><span style="color: #008000">//get connectionpoints</span><br />ProviderConnectionPoint providerConnectionPoint = (from ProviderConnectionPoint conn <span style="color: #0000ff">in</span> manager.GetProviderConnectionPoints(providerPart)<br /> <span style="color: #0000ff">where</span> conn.ID == providerConnectionId<br /> select conn).FirstOrDefault();<br /><br />ConsumerConnectionPoint consumerConnectionPoint = (from ConsumerConnectionPoint conn <span style="color: #0000ff">in</span> manager.GetConsumerConnectionPoints(consumerPart)<br /> <span style="color: #0000ff">where</span> conn.ID == consumerConnectionId<br /> select conn).FirstOrDefault();</pre>
<br /></div>
<p>Add a WebPartConnection using WebPartManager.SPConnectWebParts, and pass along the transformer.</p>
<div id="codeSnippetWrapper">
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #008000">// connect the webparts</span><br />manager.SPConnectWebParts(providerPart, providerConnectionPoint, consumerPart, consumerConnectionPoint, transformer);</pre>
<br /></div>
<div>That’s it.
<br /></div>
</div> Koen van der Lindenhttp://www.blogger.com/profile/09745561653129473651noreply@blogger.com3tag:blogger.com,1999:blog-4463898250776378608.post-3420616068778188642011-02-18T07:41:00.001+01:002011-02-18T09:11:22.891+01:00Add SPNavigation Heading without link functionality to QuickLaunch<p>Adding items to the Quicklaunch or TopNavigation is easy. However adding a heading to the Quicklaunch without the link functionality is not possible by using the basic SharePoint 2010 API. In this post I’ll show you how to create a navigation item, transform it into a heading without link functionality, and add it to the Quicklaunch. </p> <p><strong>The options:</strong></p> <ol> <li>Create a <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.navigation.spnavigationnode.aspx">SPNavigationNode</a> <br />add it to navigation using <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.navigation.spnavigation.addtoquicklaunch.aspx">spWeb.</a><a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.navigation.spnavigation.addtoquicklaunch.aspx">Navigation.AddToQuickLaunch</a>(SPNavigationNode node, SPQuickLaunchHeading heading), where <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.navigation.spquicklaunchheading.aspx">heading</a> is an enum of some default SP2010 headings. </li> <li>Create a <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.navigation.spnavigationnode.aspx">SPNavigationNode</a> <br />Get <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.navigation.spnavigationnodecollection.aspx">SPNavigationNodeCollection</a> from <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.navigation.spnavigation.quicklaunch.aspx">spWeb.Navigation.QuickLaunch</a> <br />Add <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.navigation.spnavigationnode.aspx">SPNavigationNode</a> to the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.navigation.spnavigationnodecollection.aspx">SPNavigationNodeCollection</a> using methods like AddAsFirst, or AddAsLast </li> </ol> <p>As option 1 can only to add items to default SP2010 headings. So we need to go for option 2.</p> <p><strong> <br />The problem <br /></strong>Option 2 can only add a heading navigation node to the quicklaunch that has a link. When you use the following code it will create a heading, however it will link to the ‘base url’ of the current SPWeb.</p> <div> <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #008000">// Create the node.</span><br />SPNavigationNodeCollection quicklaunchNav = web.Navigation.QuickLaunch;<br /><br /><span style="color: #008000">// Create heading</span><br />SPNavigationNode headerNode = <span style="color: #0000ff">new</span> SPNavigationNode(headerTitle, <span style="color: #0000ff">string</span>.Empty, <span style="color: #0000ff">true</span>);<br />headerNode = quicklaunchNav.AddAsLast(headerNode);<br /> <br /><span style="color: #008000">// Add subnode to heading.</span><br />SPNavigationNode node = <span style="color: #0000ff">new</span> SPNavigationNode(<span style="color: #006080">"title"</span>, <span style="color: #006080">"url"</span>, <span style="color: #0000ff">true</span>);<br />headerNode.Children.AddAsLast(node);</pre>
</div>
<div> </div>
<div>
<br /> <strong>The Solution
<br /></strong>The difference between a navigation item and a heading navigation item are some value in the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.navigation.spnavigationnode.properties.aspx">NavigationNode.Properties</a> HashTable.</div>
<p>To create a heading use the following code.</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">class</span> SPNavigationNodeExtensions<br />{<br /> <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> MakeHeaderNode(<span style="color: #0000ff">this</span> SPNavigationNode node)<br /> {<br /> node.Properties[<span style="color: #006080">"BlankUrl"</span>] = <span style="color: #006080">"True"</span>;<br /> node.Properties[<span style="color: #006080">"LastModifiedDate"</span>] = DateTime.Now;<br /> node.Properties[<span style="color: #006080">"Target"</span>] = <span style="color: #006080">""</span>;<br /> node.Properties[<span style="color: #006080">"vti_navsequencechild"</span>] = <span style="color: #006080">"true"</span>;<br /> node.Properties[<span style="color: #006080">"UrlQueryString"</span>] = <span style="color: #006080">""</span>;<br /> node.Properties[<span style="color: #006080">"CreatedDate"</span>] = DateTime.Now;<br /> node.Properties[<span style="color: #006080">"Description"</span>] = <span style="color: #006080">""</span>;<br /> node.Properties[<span style="color: #006080">"UrlFragment"</span>] = <span style="color: #006080">""</span>;<br /> node.Properties[<span style="color: #006080">"NodeType"</span>] = <span style="color: #006080">"Heading"</span>;<br /> node.Properties[<span style="color: #006080">"Audience"</span>] = <span style="color: #006080">""</span>;<br /> node.Update();<br /> }<br />}</pre>
<br /></div>
<div>As you can see, the “BlankUrl'” = True, and NodeType = “Heading”. Using the Update method it saves changes of the properties.</div>
<div>It’s now possible to transform the heading node using this extension method.</div>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #008000">//Transform Node into Header.</span><br />headerNode.MakeHeaderNode();</pre>
<br /></div>
<p>The final code is:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #008000">// Create the node.</span><br />SPNavigationNodeCollection quicklaunchNav = web.Navigation.QuickLaunch;<br /><br /><span style="color: #008000">// Create heading</span><br />SPNavigationNode headerNode = <span style="color: #0000ff">new</span> SPNavigationNode(<span style="color: #006080">"HeadingTitle"</span>, <span style="color: #0000ff">string</span>.Empty, <span style="color: #0000ff">true</span>);<br />headerNode = quicklaunchNav.AddAsLast(headerNode);<br /><br /><span style="color: #008000">//Transform Node into Header.</span><br />headerNode.MakeHeaderNode();<br /> <br /><span style="color: #008000">// Add subnode to heading.</span><br />SPNavigationNode node = <span style="color: #0000ff">new</span> SPNavigationNode(<span style="color: #006080">"title"</span>, <span style="color: #006080">"url"</span>, <span style="color: #0000ff">true</span>);<br />headerNode.Children.AddAsLast(node);<br /></pre>
<br />At this point you’ll have a heading with '”HeadingTitle” that doesn’t link. It has a sub navigation item “title”, that links to “url”. Also thanks to Matthijs Woolderink (<a href="http://twitter.com/#!/MWoolderink">@MWoolderink</a>) for some background information.</div>
</div> Koen van der Lindenhttp://www.blogger.com/profile/09745561653129473651noreply@blogger.com14tag:blogger.com,1999:blog-4463898250776378608.post-16566439994375813152011-02-16T17:42:00.001+01:002011-02-16T17:42:47.230+01:00Reminder about Content Types<p>When constructing a ContentType in the elements file you’ll reference to existing Site Columns.</p> Example Content Type: <div id="codeSnippetWrapper"> <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff"><</span><span style="color: #800000">Elements</span> <span style="color: #ff0000">xmlns</span><span style="color: #0000ff">="http://schemas.microsoft.com/sharepoint/"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">ContentType</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="0x010055180D0A5202894F9E64FC9D6D4A86B7"</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="EditionCT"</span> <span style="color: #ff0000">Group</span><span style="color: #0000ff">="Test"</span> <span style="color: #ff0000">Inherits</span><span style="color: #0000ff">="true"</span> <span style="color: #ff0000">Hidden</span><span style="color: #0000ff">="false"</span> <span style="color: #ff0000">ReadOnly</span><span style="color: #0000ff">="false"</span> <span style="color: #ff0000">Sealed</span><span style="color: #0000ff">="false"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">FieldRefs</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">FieldRef</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="71316cea-40a0-49f3-8659-f0cefdbdbd4f"</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="ArticleStartDate"</span> <span style="color: #ff0000">DisplayName</span><span style="color: #0000ff">="Article Date"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">FieldRef</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="64cd368d-2f95-4bfc-a1f9-8d4324ecb007"</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="StartDate"</span> <span style="color: #ff0000">DisplayName</span><span style="color: #0000ff">="Start Date"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">FieldRef</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="919f30d5-31f1-478f-bda5-84f595340392"</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="EndDate1"</span> <span style="color: #ff0000">DisplayName</span><span style="color: #0000ff">="End Date"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">FieldRef</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="d2132670-ec6e-4fc7-af38-0ca09a364b80"</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="Send"</span> <span style="color: #ff0000">DisplayName</span><span style="color: #0000ff">="Send"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">FieldRef</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="8adac618-8387-4c39-ad9a-ed6c17084d3a"</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="Send_x0020_Date"</span> <span style="color: #ff0000">DisplayName</span><span style="color: #0000ff">="Send Date"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">FieldRef</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="d1fc4f17-b0f7-4177-9f94-5b32cbdd2d5a"</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="Send_x0020_To"</span> <span style="color: #ff0000">DisplayName</span><span style="color: #0000ff">="Send To"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">FieldRef</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="cc69c48f-5536-4478-9172-a79468a32afa"</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="FinalSubmissionDate"</span> <span style="color: #ff0000">DisplayName</span><span style="color: #0000ff">="FinalSubmissionDate"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">FieldRef</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="cd8a6351-3235-4eb2-857d-87975bb8cb90"</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="ReminderDays"</span> <span style="color: #ff0000">DisplayName</span><span style="color: #0000ff">="ReminderDays"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">FieldRef</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="bcf32df2-5191-43d7-a1a4-fdb17acccb98"</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="SendReminderAt"</span> <span style="color: #ff0000">DisplayName</span><span style="color: #0000ff">="SendReminderAt"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">FieldRefs</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">ContentType</span><span style="color: #0000ff">></span><br /><span style="color: #0000ff"></</span><span style="color: #800000">Elements</span><span style="color: #0000ff">></span></pre>
</div>
<div> </div>
Example SiteColumn:
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff"><</span><span style="color: #800000">Field</span> <span style="color: #ff0000">Type</span><span style="color: #0000ff">="Boolean"</span> <span style="color: #ff0000">DisplayName</span><span style="color: #0000ff">="Send"</span> <span style="color: #ff0000">Group</span><span style="color: #0000ff">="Base"</span> <span style="color: #ff0000">EnforceUniqueValues</span><span style="color: #0000ff">="FALSE"</span> <span style="color: #ff0000">Indexed</span><span style="color: #0000ff">="FALSE"</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="{d2132670-ec6e-4fc7-af38-0ca09a364b80}"</span> <span style="color: #ff0000">SourceID</span><span style="color: #0000ff">="{b6366c11-b4ce-408c-8175-952b9a7800d4}"</span> <span style="color: #ff0000">StaticName</span><span style="color: #0000ff">="Send"</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="Send"</span> <span style="color: #ff0000">ShowInNewForm</span><span style="color: #0000ff">="FALSE"</span> <span style="color: #ff0000">ShowInEditForm</span><span style="color: #0000ff">="FALSE"</span> <span style="color: #0000ff">/></span></pre>
</div>
<div> </div>
<div>One thing did cost me a few hours to find out. When activating the feature the Content Type <strong>EditionCT </strong>was corrupt. It showed the <strong>Send</strong> column was of type DateTime, it was defined as a Boolean. In the Site Column overview it did show as a boolean. So only the content type was corrupted.
<br /></div>
<div>Site Column:</div>
<div><a href="http://lh3.ggpht.com/_DO_9NbckVuk/TVv-fdCGyOI/AAAAAAAAAII/8Ub3KlOSuig/s1600-h/image%5B3%5D.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_DO_9NbckVuk/TVv-fgaOV0I/AAAAAAAAAIM/ZqdOccRBYXk/image_thumb%5B1%5D.png?imgmax=800" width="469" height="16" /></a></div>
<div> </div>
<div>Content Type in Site Settings (nothing wrong, you think):</div>
<div><a href="http://lh4.ggpht.com/_DO_9NbckVuk/TVv-gH_8HHI/AAAAAAAAAIQ/LzV7MPkLI6U/s1600-h/image%5B7%5D.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_DO_9NbckVuk/TVv-gQmr4fI/AAAAAAAAAIU/GKGH-7a_wwg/image_thumb%5B3%5D.png?imgmax=800" width="467" height="99" /></a></div>
<div> </div>
<div>Content Type in SharePoint Manager 2010 (its corrupt):</div>
<div><a href="http://lh5.ggpht.com/_DO_9NbckVuk/TVv-glwbdLI/AAAAAAAAAIY/Z29AhDts4F8/s1600-h/image%5B11%5D.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_DO_9NbckVuk/TVv-g6op-1I/AAAAAAAAAIc/bm0B3btsgn0/image_thumb%5B5%5D.png?imgmax=800" width="517" height="141" /></a></div>
<div> </div>
<div>Content Type when added to a list (also corrupted):</div>
<div><a href="http://lh3.ggpht.com/_DO_9NbckVuk/TVv-hVoK40I/AAAAAAAAAIg/9GAeSN6LWKs/s1600-h/image%5B15%5D.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_DO_9NbckVuk/TVv-hp3ONSI/AAAAAAAAAIk/HnDt68wTSXs/image_thumb%5B7%5D.png?imgmax=800" width="438" height="129" /></a></div>
<div> </div>
<div> </div>
<div>Than I noticed the <strong>ArticleStartDate </strong>was a site column from the Publishing framework. This site collection feature wasn’t activated and so that appropriate fields were not available, one of them was the ArticleStartDate. Strange thing was that SharePoint didn’t report an error when constructing the content type, but just corrupted the Content Type.</div>
<div> </div>
<div>So keep in mind to have the fields available when provisioning the Content Type, and as you can see, strange things can happen.</div> Koen van der Lindenhttp://www.blogger.com/profile/09745561653129473651noreply@blogger.com0tag:blogger.com,1999:blog-4463898250776378608.post-58366281176899098192011-02-13T12:36:00.001+01:002017-04-05T15:04:34.479+02:00How to Customize the SharePoint List "NewForm" using VS2010 instead of SharePoint DesignerMost blogs show you how to customize the NewForm of a SharePoint List by using SharePoint Designer. However when you need to support/maintain a SharePoint Solution you really should use a Solution (.wsp). Easiest way is to use VS2010. In this blog I demonstrate how to create a customized NewForm, this means. When a user clicks 'New Item' in the list it will render a customized version of the 'New Form'. It's possible to add additional Web Parts and content. In this version it will however still use the default <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webpartpages.listformwebpart.aspx" target="_blank">ListFormWebPart</a> to render the new-item form.<br />
I assume you already have created custom Fields (Site Columns) and Content Types in VS2010.<br />
The steps to take are:<br />
<ol>
<li>Create ListDefinition</li>
<li>(optional) Create ListInstance</li>
<li>Create a custom page that will hold the customizations</li>
<li>Customize ListDefinition schema</li>
<li>Deploy the solution, activate feature</li>
</ol>
<strong>Step 1: Create ListDefinition</strong><br />
In VS2010, you have a choice to create a new ListDefinition based on Content Type and just a plain ListDefinition. In this demo I chose the latter.<br />
<br />
I want to create a List Definition based on Custom list. I also create to create a List Instance (<strong>Step 2)</strong> so after deployment I immediately have a custom list created<strong>.</strong><br />
<br />
<strong>Step 3: Create a customized NewForm</strong><br />
In schema.xml of the ListDefinition you see this line: <br /><Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" /><br />
The SetupPath point to the 14-hive\templates folder. So In this case it will provision a NewForm.aspx based on the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\Pages\form.aspx <br />You don't want to change this out-of-the-box page. It will void you support from Microsoft ;-).<br />
So make a copy, copy it into the ListDefinition project and rename it to MyNewForm.aspx. Make sure you include MyNewForm.aspx into the VS2010 project and set the 'Deployment Type' to <strong>ElementFile</strong>, this will deployed the file to the feature directory. It should now look like this in VS2010.<br />
<br />
Add some content to the NewForm: <br />Open the MyNewForm.aspx and look for the PlaceHolderMain ContentPlaceHolder (Line 244). <br />Put some content like <h1>Hello Customized World</h1> in front of the the <table …> a few line below.<br />
Add a Web Part Zone to the NewForm: <br />Add: <WebPartPages:WebPartZone runat="server" FrameType="None" ID="Top" Title="loc:Top" /> after the <h1>Hello… <br /> <br />So it will look like this:<br />
<div id="codeSnippetWrapper" style="background-color: #f4f4f4; border-bottom: silver 1px solid; border-left: silver 1px solid; border-right: silver 1px solid; border-top: silver 1px solid; cursor: text; direction: ltr; font-family: "courier new" , "courier" , monospace; font-size: 8pt; line-height: 12pt; margin: 20px 0px 10px; max-height: 200px; overflow: auto; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px; text-align: left; width: 97.5%;">
<pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: "courier new" , "courier" , monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;"><span style="color: blue;"><</span><span style="color: maroon;">asp:Content</span> <span style="color: red;">ContentPlaceHolderId</span><span style="color: blue;">="PlaceHolderMain"</span> <span style="color: red;">runat</span><span style="color: blue;">="server"</span><span style="color: blue;">></span>
<span style="color: blue;"><</span><span style="color: maroon;">SharePoint:UIVersionedContent</span> <span style="color: red;">UIVersion</span><span style="color: blue;">="4"</span> <span style="color: red;">runat</span><span style="color: blue;">="server"</span><span style="color: blue;">></span>
<span style="color: blue;"><</span><span style="color: maroon;">ContentTemplate</span><span style="color: blue;">></span>
<span style="color: blue;"><</span><span style="color: maroon;">div</span> <span style="color: red;">style</span><span style="color: blue;">="padding-left:5px"</span><span style="color: blue;">></span>
<span style="color: blue;"></</span><span style="color: maroon;">ContentTemplate</span><span style="color: blue;">></span>
<span style="color: blue;"></</span><span style="color: maroon;">SharePoint:UIVersionedContent</span><span style="color: blue;">></span>
<span style="color: blue;"><</span><span style="color: maroon;">h1</span><span style="color: blue;">></span>Hello Customized World<span style="color: blue;"></</span><span style="color: maroon;">h1</span><span style="color: blue;">></span>
<span style="color: blue;"><</span><span style="color: maroon;">WebPartPages:WebPartZone</span> <span style="color: red;">runat</span><span style="color: blue;">="server"</span> <span style="color: red;">FrameType</span><span style="color: blue;">="None"</span> <span style="color: red;">ID</span><span style="color: blue;">="Top"</span> <span style="color: red;">Title</span><span style="color: blue;">="loc:Top"</span> <span style="color: blue;">/></span>
<span style="color: blue;"><</span><span style="color: maroon;">table</span> <span style="color: red;">cellpadding</span><span style="color: blue;">="0"</span> <span style="color: red;">cellspacing</span><span style="color: blue;">="0"</span> <span style="color: red;">id</span><span style="color: blue;">="onetIDListForm"</span> <span style="color: red;">style</span><span style="color: blue;">="width:100%"</span><span style="color: blue;">></span>
<span style="color: blue;"><</span><span style="color: maroon;">tr</span><span style="color: blue;">></span>
<span style="color: blue;"><</span><span style="color: maroon;">td</span><span style="color: blue;">></span>
<span style="color: blue;"><</span><span style="color: maroon;">WebPartPages:WebPartZone</span> <span style="color: red;">runat</span><span style="color: blue;">="server"</span> <span style="color: red;">FrameType</span><span style="color: blue;">="None"</span> <span style="color: red;">ID</span><span style="color: blue;">="Main"</span> <span style="color: red;">Title</span><span style="color: blue;">="loc:Main"</span> <span style="color: blue;">/></span></pre>
<br /></div>
Save the changes ;-).<br />
<strong>Step 4 Change the Schema.xml</strong><br />
Now we have created a custom page, however we need to tell the ListDefinition to use the customize NewForm. To do this, we need to change the <a href="http://msdn.microsoft.com/en-us/library/ms478121.aspx" target="_blank">Form element</a> in the ListDefinition schema.xml<br />
Code Before:
<br />
<br />
<div id="codeSnippetWrapper" style="background-color: #f4f4f4; border-bottom: silver 1px solid; border-left: silver 1px solid; border-right: silver 1px solid; border-top: silver 1px solid; cursor: text; direction: ltr; font-family: "courier new" , "courier" , monospace; font-size: 8pt; line-height: 12pt; margin: 20px 0px 10px; max-height: 200px; overflow: auto; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px; text-align: left; width: 97.5%;">
<pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: "courier new" , "courier" , monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;"><span style="color: blue;"><</span><span style="color: maroon;">Form</span> <span style="color: red;">Type</span><span style="color: blue;">="NewForm"</span> <span style="color: red;">Url</span><span style="color: blue;">="NewForm.aspx"</span> <span style="color: red;">SetupPath</span><span style="color: blue;">="pages\form.aspx"</span> <span style="color: red;">WebPartZoneID</span><span style="color: blue;">="Main"</span> <span style="color: blue;">/></span></pre>
<br /></div>
<br />
Code After:<br />
<div id="codeSnippetWrapper" style="background-color: #f4f4f4; border-bottom: silver 1px solid; border-left: silver 1px solid; border-right: silver 1px solid; border-top: silver 1px solid; cursor: text; direction: ltr; font-family: "courier new" , "courier" , monospace; font-size: 8pt; line-height: 12pt; margin: 20px 0px 10px; max-height: 200px; overflow: auto; padding-bottom: 4px; padding-left: 4px; padding-right: 4px; padding-top: 4px; text-align: left; width: 97.5%;">
<pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: "courier new" , "courier" , monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;"><span style="color: blue;"><</span><span style="color: maroon;">Form</span> <span style="color: red;">Type</span><span style="color: blue;">="NewForm"</span> <span style="color: red;">Url</span><span style="color: blue;">="NewForm.aspx"</span> <span style="color: red;">Path</span><span style="color: blue;">="MyNewForm.aspx"</span> <span style="color: red;">WebPartZoneID</span><span style="color: blue;">="Main"</span> <span style="color: red;">Default</span><span style="color: blue;">="TRUE"</span> <span style="color: red;">UseDefaultListFormWebPart</span><span style="color: blue;">="False"</span> <span style="color: red;">WebPartOrder</span><span style="color: blue;">="1"</span><span style="color: blue;">></span>
<span style="color: blue;"><</span><span style="color: maroon;">WebParts</span><span style="color: blue;">></span>
<span style="color: blue;"><</span><span style="color: maroon;">AllUsersWebPart</span> <span style="color: red;">WebPartZoneID</span><span style="color: blue;">="Main"</span> <span style="color: red;">WebPartOrder</span><span style="color: blue;">="1"</span><span style="color: blue;">></span>
<span style="color: blue;"><!</span>[CDATA[
<span style="color: blue;"><</span><span style="color: maroon;">WebPart</span> <span style="color: red;">xmlns</span><span style="color: blue;">="http://schemas.microsoft.com/WebPart/v2"</span><span style="color: blue;">></span>
<span style="color: blue;"><</span><span style="color: maroon;">Assembly</span><span style="color: blue;">></span>Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c<span style="color: blue;"></</span><span style="color: maroon;">Assembly</span><span style="color: blue;">></span>
<span style="color: blue;"><</span><span style="color: maroon;">TypeName</span><span style="color: blue;">></span>Microsoft.SharePoint.WebPartPages.ListFormWebPart<span style="color: blue;"></</span><span style="color: maroon;">TypeName</span><span style="color: blue;">></span>
<span style="color: blue;"><</span><span style="color: maroon;">PageType</span><span style="color: blue;">></span>PAGE_NEWFORM<span style="color: blue;"></</span><span style="color: maroon;">PageType</span><span style="color: blue;">></span>
<span style="color: blue;"></</span><span style="color: maroon;">WebPart</span><span style="color: blue;">></span>]]<span style="color: blue;">></span>
<span style="color: blue;"></</span><span style="color: maroon;">AllUsersWebPart</span><span style="color: blue;">></span>
<span style="color: blue;"><</span><span style="color: maroon;">AllUsersWebPart</span> <span style="color: red;">WebPartZoneID</span><span style="color: blue;">="Top"</span> <span style="color: red;">WebPartOrder</span><span style="color: blue;">="1"</span><span style="color: blue;">></span>
<span style="color: blue;"><!</span>[CDATA[
<span style="color: blue;"><</span><span style="color: maroon;">WebPart</span> <span style="color: red;">xmlns</span><span style="color: blue;">="http://schemas.microsoft.com/WebPart/v2"</span> <span style="color: red;">xmlns:iwp</span><span style="color: blue;">="http://schemas.microsoft.com/WebPart/v2/Image"</span><span style="color: blue;">></span>
<span style="color: blue;"><</span><span style="color: maroon;">Assembly</span><span style="color: blue;">></span>Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c<span style="color: blue;"></</span><span style="color: maroon;">Assembly</span><span style="color: blue;">></span>
<span style="color: blue;"><</span><span style="color: maroon;">TypeName</span><span style="color: blue;">></span>Microsoft.SharePoint.WebPartPages.ImageWebPart<span style="color: blue;"></</span><span style="color: maroon;">TypeName</span><span style="color: blue;">></span>
<span style="color: blue;"><</span><span style="color: maroon;">FrameType</span><span style="color: blue;">></span>None<span style="color: blue;"></</span><span style="color: maroon;">FrameType</span><span style="color: blue;">></span>
<span style="color: blue;"><</span><span style="color: maroon;">Title</span><span style="color: blue;">></span>My Custom Image<span style="color: blue;"></</span><span style="color: maroon;">Title</span><span style="color: blue;">></span>
<span style="color: blue;"><</span><span style="color: maroon;">iwp:ImageLink</span><span style="color: blue;">></span>/_layouts/images/homepage.gif<span style="color: blue;"></</span><span style="color: maroon;">iwp:ImageLink</span><span style="color: blue;">></span>
<span style="color: blue;"><</span><span style="color: maroon;">iwp:AlternativeText</span><span style="color: blue;">></span>Logo<span style="color: blue;"></</span><span style="color: maroon;">iwp:AlternativeText</span><span style="color: blue;">></span>
<span style="color: blue;"></</span><span style="color: maroon;">WebPart</span><span style="color: blue;">></span>]]<span style="color: blue;">></span>
<span style="color: blue;"></</span><span style="color: maroon;">AllUsersWebPart</span><span style="color: blue;">></span>
<span style="color: blue;"></</span><span style="color: maroon;">WebParts</span><span style="color: blue;">></span>
<span style="color: blue;"></</span><span style="color: maroon;">Form</span><span style="color: blue;">></span></pre>
<br /></div>
What I've done is:<br />
<ul>
<li>instead of using the default /pages/form.aspx, I told it to use the MyNewForm.aspx (So I changed SetupPath="pages/form.aspx" to Path="MyNewForm.aspx", it should not look into the template directory but in the feature directory, so SetupPath => Path…). The file will still be accessible with url NewForm.aspx. You can change that if you want. </li>
<li>UseDefaultListFormWebPart="False", it will not add a default ListFormWebPart, but it will process the <WebParts> child elements.</li>
<li>The <WebParts> child elements are used to place web part on the Custom MyNewForm.aspx</li>
<ul>
<li>first web part is a ListFormWebPart. When setting the PageType to PAGE_NEWFORM, it will add a ListFormWebPart that will handle the 'New Item' rendering, make sure the WebPartZoneID matches with the ZoneID's in the customized form. Default there's a Main ZoneID.</li>
<li>second web part is a Image Web Part, showing a default MS SharePoint logo. This web part will be placed in the Top WebPartZoneID (our custom WebPartZone).</li>
</ul>
</ul>
<strong>Final Step: Deploy solution and activate feature.</strong><br />
Deploy the solution using VS2010.
<br />Visit the site where you deployed the solution. If VS2010 didn't automatically activated the feature, you should go to Site Settings, Manage Site Features and look for feature 'CustomListDemo Feature1' (This is why a naming convention is recommended ;-)). So make sure it's activated.<br />
As the feature included a listinstance a list is created. The list name is: "CustomListDemo - ListInstance1".
<br />Go to this list and click on 'New Item'.<br />
This will be the result:<br />
<br />
As you can see. The custom NewForm, including some custom content, a custom Web Part and the default ListFormWebPart. This is just a simple example. But you could go wild on the content and on adding your own Web Parts. It's also possible to change the template the ListFormWebPart uses. But that's for another day…
<br />
<br />Read some more about <a href="http://msdn.microsoft.com/en-us/library/aa544142.aspx" target="_blank">Customizing Form</a>.<br />
<a href="http://twitter.com/#!/kvdlinden" target="_blank">You can follow me on twitter</a>Koen van der Lindenhttp://www.blogger.com/profile/09745561653129473651noreply@blogger.com10tag:blogger.com,1999:blog-4463898250776378608.post-42058248596096401802011-02-03T20:28:00.001+01:002017-04-05T15:09:53.561+02:00Tombstoning MVVMLight ViewModels with an ApplicationBar using SilverlightSerializerI've first implemented Tombstoning <a href="http://mvvmlight.codeplex.com/" target="_blank">MVVMLight</a> ViewModels using the default DataContractSerializer. I save the ViewModel when closing the application to persistent storage by using the IsolatedStorageSettings.ApplicationSettings. When deactivating the application I saved the ViewModels to transient storage using PhoneApplicationService.Current.State. This method has some limitations regarding maximum storage size. Second problem was that the MVVMLight ViewModelBase class constructor was not public and therefor could not be serialized. I fixed this by just downloading the sources and use the new assemblies.<br />
I wasn't really satisfied. When I was at the <a href="http://www.dotned.nl/" target="_blank">DotNed</a> meeting at Qurius there was a discussion about saving states and what serializers would be a good option. The <a href="http://whydoidoit.com/silverlight-serializer/" target="_blank">SilverLightSerializer</a> was the one I remembered, so back at home I did some digging and found that <a href="http://www.blogger.com/profile/02182444268071162776" target="_blank">LocalJoost</a> <a href="http://dotnetbyexample.blogspot.com/2011/01/tombstoning-mvvmlight-viewmodels-with.html" target="_blank">blogged</a> about it. <br />
I implemented the <a href="http://whydoidoit.com/silverlight-serializer/" target="_blank">SilverLightSerializer</a> and just needed to replace the saving and loading state parts. Than I tested the application and found out the application bar was gone after a deactivate / activate cycle.<br />
Before deactivating: <br />
Then do a 'Start' and 'Back', it will activate in a state like this: <br />
I also had this problem before using the DataContractSerializer. That was fixed by decorating the public <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.applicationbar(v=vs.92).aspx" target="_blank">ApplicationBar</a> properties with <strong>[IgnoreDataMember] </strong>attribute. The <a href="http://whydoidoit.com/silverlight-serializer/" target="_blank">SilverLightSerializer</a> skips properties from being serialized which are decorated with the <strong>[DoNotSerialize]</strong> attribute. So I replaced the <strong>[IgnoreDataMember]</strong> with <strong>[DoNotSerialize]</strong> and the ApplicationBar was back again.<br />
Hopes this saved you some hours of searching and testing.Koen van der Lindenhttp://www.blogger.com/profile/09745561653129473651noreply@blogger.com0tag:blogger.com,1999:blog-4463898250776378608.post-79528930230961024132011-01-16T20:41:00.001+01:002011-01-16T20:41:10.232+01:00Silverlight Toolbox GestureListener not working great when developing using Remote Desktop<p> <br />The <a href="http://silverlight.codeplex.com/" target="_blank">Silverlight for Windows Phone Toolkit</a> is working fine in normal environments, great toolkit. However when I started developing WP7 apps in the living room and used a Remote Desktop connection to the development machine I encountered very bad gesture responses in the Windows 7 Emulator. The Flick gesture on the emulator screen didn't do anything (well about 1 out of 100). Doing it again 1 minute later on de development machine without RDS and it worked <strong>all the time</strong>. Other gestures worked fine. Maybe it's something with the mouse events?</p> <p>The XAML code I used:</p> <div id="codeSnippetWrapper"> <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff"><</span><span style="color: #800000">toolkit:GestureService.GestureListener</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">toolkit:GestureListener</span> <span style="color: #ff0000">Flick</span><span style="color: #0000ff">="GestureListener_Flick"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">toolkit:GestureListener</span><span style="color: #0000ff">></span><br /><span style="color: #0000ff"></</span><span style="color: #800000">toolkit:GestureService.GestureListener</span><span style="color: #0000ff">></span></pre>
<br /></div>
<p>Code behind:</p>
<div id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1"> 1:</span> <span style="color: #0000ff">if</span> (ViewModel.ViewModelLocator.MainStatic.TossCmd.CanExecute(e))</pre>
<!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2"> 2:</span> {</pre>
<!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3"> 3:</span> ViewModel.ViewModelLocator.MainStatic.TossCmd.Execute(e);</pre>
<!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4"> 4:</span> }</pre>
<!--CRLF--></div>
</div>
<p>Setting a breakpoint on line 1 never kicked in.</p> Koen van der Lindenhttp://www.blogger.com/profile/09745561653129473651noreply@blogger.com0tag:blogger.com,1999:blog-4463898250776378608.post-251667692372748042011-01-07T19:47:00.000+01:002011-01-07T19:48:07.300+01:00Property Bag issues<p>This time a minor blog post. It’s more for myself so I don’t forget. </p> <p>This time it’s about the property bag in various object in SharePoint 2010. The problem I came across was how to remove a property bag key-value. But lets start at the beginning.</p> <div id="codeSnippetWrapper">1- Add an value to the property bag.</div> <div> </div> <div id="codeSnippetWrapper"> <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #008000">//set value on (a new) Property bag </span><br /><span style="color: #0000ff">if</span> (web.Properties.ContainsKey(<span style="color: #006080">"ExpireOn"</span>)) <br />{ <br /> web.Properties[<span style="color: #006080">"ExpireOn"</span>] = <span style="color: #006080">"some sting"</span>; <br />} <br /><span style="color: #0000ff">else</span> <br />{ <br /> web.Properties.Add(<span style="color: #006080">"ExpireOn"</span>,<span style="color: #006080">"some string"</span>); <br />}<br />web.Properties.Update();</pre>
<br /></div>
<p>2- Remove an item from property bag</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #008000">//Remove Property bag </span><br /><span style="color: #008000">//Does not work </span><br /><span style="color: #008000">////web.Properties.Remove("ExpireOn"); </span><br /><span style="color: #008000">////web.Properties.Update(); </span><br /> <br /><span style="color: #008000">//Does work </span><br />web.Properties[<span style="color: #006080">"ExpireOn"</span>] = <span style="color: #0000ff">null</span>; <br />web.Properties.Update();</pre>
<br /></div>
<div>As you can see, using <a href="http://msdn.microsoft.com/EN-US/library/k5d8396x(v=VS.90)" target="_blank">Remove</a> doesn’t work. You should set the value to null, call Update() on properties to persist the change to the database. At this point the null-ed Property bag key-value will be removed from the collection.</div> Koen van der Lindenhttp://www.blogger.com/profile/09745561653129473651noreply@blogger.com2tag:blogger.com,1999:blog-4463898250776378608.post-48602638793017519652010-10-17T11:59:00.001+02:002017-04-05T15:09:33.008+02:00Virtual Box Virtual Images won’t start after upgradingAfter a few weeks of vacation and some other projects I started using Virtual Box again. As as usual I needed to update the application. I downloaded the new version (3.2.10), also noticed that it’s now all Oracle stuff. I started my a old virtual machine, however I always failed after a few seconds. Created a new virtual machine and again.<br />
<br />
I tracked it down to the Storage section. Normally the VM configuration used the IDE controller. However in the new version I noticed that the virtual hard disk was mounted on the SATA controller.<br />
<br />
So by default it looks like it attaches the VHD to the SATA Controller. I changed this back, so the VHD is now mounted on the IDE controller.<br />
<br />
This fixed the problem, I can now start the VHD without problems. Probably an existing Windows 2008 VHD doesn’t like switching from IDE to SATA.Koen van der Lindenhttp://www.blogger.com/profile/09745561653129473651noreply@blogger.com0tag:blogger.com,1999:blog-4463898250776378608.post-61131507385635043932010-05-10T14:39:00.001+02:002017-04-05T15:09:11.809+02:00Running Hyper-V images with Sun VirtualBoxIf you want to run your Hyper-V created or downloaded machines on Sun VirtualBox, you might experience some problems. When settings in VirtualBox are incorrect the image won’t start. I first thought it’s was about conflict with Hyper-V Integration Services or incompatibility between the Hyper-V vhd and VirtualBox. But luckily it’s just some configuration of VirtualBox to make it work.<br />
So I have a SharePoint 2010 Hyper-V image and Next week I need to give a training and needed to use Sun VirtualBox as Hyper-V doesn’t run on Windows XP. So I copied the Hyper-V virtual hard disk to my local machine and followed the following steps.<br />
<ul>
<li>Start VirtualBox </li>
<li>Create a new Virtual Machine </li>
<li>Do the basic settings </li>
<li>Add the Hyper-V virtual hard disk </li>
<li>Set IO APIC enabled in the Systems Tab (this is is important, otherwise it will hang after like 20 seconds on startup) </li>
</ul>
<br />
<ul>
<li>Start the VM in VirtualBox </li>
<li>Stopped the Hyper-V services and set startup type to: Manual</li>
</ul>
<br />
<ul>
<li>Installed the VBoxGuestAdditions for better integration with the virtual machine.</li>
</ul>
If you didn’t set the correct settings the virtual machine does start however after about 20 seconds (depending of your hardware) it hangs forever, and looks like this:<br />
Koen van der Lindenhttp://www.blogger.com/profile/09745561653129473651noreply@blogger.com1