Lync 2010 for Windows Phone 7 is now Available

by Luke 12. December 2011 03:40

Hot off the app market. If you have Lync installed in your organization and have a Windows Phone 7 go ahead and swing over to the marketplace and search Lync 2010. The app is free and takes a few minutes to connect. http://www.windowsphone.com/en-US/apps/9ce93e51-5b35-e011-854c-00237de2db9e

Word on the street Lyn is also available for Android and iPhone.

Tags:

WP7 | General | Lync

Encode and Decode SharePoint Internal Field Names from URL

by Luke 30. November 2011 06:19

SharePoint stores field names as XML in the database. When the field properties are viewed in the URL they are then URL Encoded to ensure there aren’t any non-url friendly characters in the URL. The best practices is to NOT put special characters into the field names. Once the field is created the internal name is permanent so go ahead and change your name after you create it.

If you have a field name like ‘Ice / Cream’ it will appear in the url as field=Ice%5Fx0020%5F%5Fx002F%5F%5Fx0020%5FCream

In order to access the fields in code, you need to reference them using the XML formatting. Before you can figure out what the XML is you need to figure out how to decode the URL. Here are a few from the above example

  • [space]    x0020
  • _                 %5F
  • /                 %2F

If we decode the above URL for just the underscores we would get:

Ice_x0020__x002F__x0020_Cream
Which reads (Ice[space][forwardslash][space]Cream)
                                  _x0020_       _x002F_       _x0020_

If we decode this further we can get the original column name: ‘Ice / Cream’

Tags:

SharePoint 2010

HTC HD7 T-Mobile FREE Tethering

by Luke 17. November 2011 05:48

If you have a Windows Phone 7 you are in for a treat!

I just ran an updated (literally 3 minutes ago) on my HTC HD7 and it now has Internet Sharing! It option wasn’t under the WIFI setup screen like I have seen in previous screen shots on the Microsoft site. Instead it is an option under Settings called Internet Sharing.

Keep in mind T-Mobile has a 2GB/month quota and anything over that is slowed down. I’ve never hit the cap with my smart phone even with Netflix. I no longer have Netflix but now with tethering I can see the potential of hitting the threshold. Happy day WP7 phone users!

Tags:

WP7

Clean Code and Squirrel Programming

by Luke 5. October 2011 03:24

I’ve been readying through the Clean Code book by Robert C. Martin. I am only a chapter or two into the book and I feel like my code is becoming much more manageable and easier to ready. Method length was probably my biggest offender. I also used to comment a lot in code but now I am writing more self describing methods and variables so I don’t need to comment as much.

I saw a squirrel this morning and it did the usual thing of running to the nearest tree. For whatever reason I thought it would be an interesting exercise to write some pseudo-code about an event they would handle; here it goes.

   1: protected void OnHumanSpotted(object sender, EventArgs e)
   2: {
   3:   List<Trees> localTrees = GetSurroundingTrees();
   4:  
   5:   Tree closestClimbableTree = GetSafestTreeToClimb(localTrees);
   6:  
   7:   if (closestClimbableTree != null)
   8:   {
   9:     Climb(closestClimbableTree);
  10:   }
  11:   else
  12:   {
  13:     FleeOnFoot();
  14:   }
  15: }

I like how you don’t need to know the implementation of any of the methods, the intent of the code is communicated through the method names. I am sure this could be improved even more by encapsulating the methods even more but it works for this simple example.

Cheers!

Tags:

General | Clean Code

New Data Protection Manager 2010 Book

by Luke 22. August 2011 04:50

A good friend and co-worker of mine just released a book on Microsoft Data Protection Manager 2010. You can pick it up for a few dollars less at the publisher’s site: https://www.packtpub.com/microsoft-data-protection-manager-2010/book. I know Steve spent a lot of time on the book and had a lot of input from a number of DPM MVPs so there’s bound to be a lot of good stuff in this book with very little fluff. Once I take a look at it I’ll include a more thorough review.

Tags:

General | General | Backup | Backup

TFS to SharePoint White Paper

by Luke 27. July 2011 03:25

I’ve been quite busy for a little over a month now, working on a considerations white paper for TFS deployment to SharePoint. The paper outlines different deployment methods and their pro/cons. If you are using TFS and do SharePoint deployment, the paper is perfect for you!

The fruit of my labor has finally released and the white paper is available for download. Swing over to RepliWeb’s site and register for the paper! http://www.repliweb.com/resources/lp/tfs2010_shp_whitepaper.php

Cheers!
Luke

Tags:

General | SharePoint 2010 | TFS

Deploy SharePoint 2010 Solutions (WSP) files from Team Foundation Server 2010 Build Part 2

by Luke 27. May 2011 06:05

In part one we configured our build machine, executed a basic build and then added some msbuild switches to out put a WSP file. Now we are going to custom the build template to allow us to execute a custom powershell script and deploy our SharePoint solution package on our build server. The steps are very involved and it was difficult to put them to words without being too wordy. If you need some assistance drop a comment on the post and I will try to get back to you. Hope you enjoy!

Step 4: Wire Up a Simple PowerShell script

Fire up notepad and type into it: Write-Host "Hello World!"

Save the file as HelloWorld.ps1.

  1. Open the command prompt
  2. To test the script the execution policy needs to be changed by executing the command: powershell set-executionpolicy remotesigned
  3. Now execute the command: powershell "& 'C:\[PathToFile]\HelloWorld.ps1'"

Note: remember to replace the [PathToFile] with the actual path of the file

Verify the output says Hello World!

Now drop the PowerShell script into the root of your project and check it into Source Control. Next we need to customize the Build process template to accept a parameter to execute our PowerShell script.

Open up the Build Template again and navigate to the Process Tab. In here click the Show details down arrow under the Build process template: heading.

clip_image002

Click the New... button

Copy the Default Template and name your new file name SharePointDeployment.xaml; Click OK.

clip_image003

Save your Build Definition and then switch over to the Source Control Explorer. Beneath the Project you are working on should be a folder named BuildProcessTemplates. Take a look inside this folder to find your new build process template. Double click your new template to open up the workflow designer.

Locate the Try Catch Action which says "Try Compile, Test, and Associate Changesets and Work Items." I like to click the up arrows in the top right corner so this entire action is collapsed. This will make it easier to find your place in the future and add items.

Now, before we can start to add new elements to our workflow we need a way to indicate which script to run when the build executes. To do this, we will use an Argument. I like to think of arguments like constructor overloads. They can optionally be set when the build is executed. This is just one aspect of arguments, for now add a new one by clicking Arguments in the bottom right and scrolling down to the bottom row. The type should be string and direction should be in.

clip_image005

Now, go to the toobox in the visual studio and from the Control Flow group add an if statement just below the Try block we collapsed previously.

Click into the Condition text box and begin typing… whoa! Intellisense, now we are getting back to familiar ground. If you have a VB.NET background you will feel at home because this workflow is implemented using VB.NET. Your condition is checking if a DeploymentScript value was given so in VB we write "DeploymentScript IsNot Nothing".

Drop a Sequence activity into the Then box of our If statement which will encapsulate our actions. For the Sequence activity name it Start Deployment.

Now drop a ConvertWorkspaceItem activity into the Sequence activity, followed by an InvokeProcess activity.

Before we can use our DeploymentScript value we are passing into our build we need to convert it to something the build process can find in the file system. We use the ConvertWorkspaceItem activity to change our path to something the build will recognize. But we will need a variable to store the value. Variables are exactly what you think they are, variables like in any other coding language. They are scoped to a location so click on the Start Deployment Sequence activity and click Variables in the bottom left. Go to the bottom and create a new one named "DeploymentScriptFilename" of type String. Notice the scope is pre-set for you to Start Deployment.

clip_image007

Now, right-click on the ConvertWorkspaceItem and choose properties, set the properties like you see in the screenshot below.

clip_image008

This activity takes our Argument "DeploymentScript" and converts it to a path the build process can find and then stores it in the "DeploymentScriptFilename" variable. Now we are ready to execute the script.

Now, it is time to setup the properties of the InvokeProcess activity exactly like the screenshot below.

clip_image010

I've pulled the full text for the Arguments property out for you here: String.Format(" ""& '{0}'"" ", DeploymentScriptFilename)

To see the output of our elegant script, drop a WriteBuildMessage activitie below the handle standard output and handle error output. For the message properties set each one to be the value of the textbox immediately above the activity.

clip_image011

Save your changes; the workflow should look like this:
clip_image012

We need to set the value of the Argument "DeploymenScript" we created. Save and check-in the Deplo

Now it is time to save and check-in our build template and PowerShell script. Open Source Control Explorer and check-in the NewBuildProcessTemplate.xaml. In solution explorer right click on your project and choose Add Existing Item. Browse to the PowerShell script and click Add. It should appear in your project root now. Check the file into source control.

Open up your build definition to the Process tab and notice the new Misc grouping with the value DeploymentScript. Before we enter a value here navigate to the Workspace tab and verify there is an entry for the project you are currently working on. It should look something like $/FOLDER/ProjectName.

Go back to the process tab and type the path to your PowerShell script file into the DeploymentScript field (eg. $/FOLDER/ProjectName/HelloWorld.ps1).

clip_image014

Save your build definition and queue up a new build. Before submitting it, click the Parameters tab and change the Logging Verbosity to Detailed. This will give us the output of our PowerShell script file.
clip_image015

When the build finishes, expand the log and locate the Hello World message. Tip: you can watch the build by double clicking on it in the Queue.
clip_image017

Step 5: Wire Up a SharePoint Deployment PowerShell script

Once this is working, it is time to expand on our PowerShell Script to deploy the SharePoint solution. In order to do this we will need to have a fairly powerful SharePoint deployment script and know 2 things:

  1. The location of the solution files
  2. The solution file name

Let's dissect the script first. Comments are preceded with the # character. The solution does quite a few things.

  1. Sets up some parameters which can be passed into the script and stores them in variables
  2. Adds the SharePoint PowerShell snap-in so we have SharePoint script context
  3. Checks for the solution in the solution store
  4. Checks if the solution is deployed and retracts it
  5. Removes the solution
  6. Adds the solution
  7. Deploys the solution
   1: #Store the name of the file we will use this later to add the solution
   2:  
   3: param ( $solutionName, $solutionFileLocation )
   4:  
   5: $solutionPackageName = [System.String]::Format("{0}", $solutionName)
   6:  
   7: $path = [System.String]::Format("{0}", $solutionFileLocation)
   8:  
   9: Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction "SilentlyContinue"
  10:  
  11: write-host "Checking for solution:" $solutionPackageName
  12:  
  13: $solution = Get-SPSolution | where-object {$_.Name -eq $solutionPackageName} 
  14:  
  15: if ($solution -ne $null) { 
  16:  
  17: write-host "Solution found"
  18:  
  19: if ($solution.Deployed -eq $true) {
  20:  
  21: write-host "Solution Installed, Uninstalling"
  22:  
  23: Uninstall-SPSolution -Identity $solutionPackageName -Local -Confirm:$false
  24:  
  25: }
  26:  
  27: write-host "Solution Uninstalled"
  28:  
  29: Remove-SPSolution -Identity $solutionPackageName -Confirm:$false
  30:  
  31: write-host "Solution Removed"
  32:  
  33: }
  34:  
  35: write-host "Adding New Solution"
  36:  
  37: Add-SPSolution -LiteralPath $path
  38:  
  39: write-host "Installing Solution"
  40:  
  41: Install-SPSolution -Identity $solutionPackageName -Local -GACDeployment
  42:  
  43: write-host "Solution Installed"

It is always a good idea to test scripts in the PowerShell ISE before adding them to your build. In my scenario I am deploying a Farm solution with GAC resources so my deployment script might be different from yours.

Now that we've dissected the script we are ready to add it to the project and deployment. Copy and paste the above script into a new PowerShell script file and add it to your project root as DeployFarmSolution.ps1 (remember to check it in).
clip_image018

Now to the two information challenges we face.

Solution File Names

I did not find a way to get these dynamically so I coded them into an Argument in the build process template. This gives me the flexibility of updating them from the GUI of the Build Definition if I decide to change the name. The name of the Argument I use is "SolutionName". It should look like the below screenshot.
clip_image019

To set the variable we need to save AND check-in the template. Then open up the build definition from Team Explorer by right-clicking on the Build and choosing Edit Build Definition. In the Process tab there should be another item in the Misc grouping named SolutionName. Put the name of the solution into this field (eg. Solution.name.wsp). While you are in here go ahead and change the DeployMent script Argument to be your new DeployFarmSolution PowerShell script.
clip_image021

Location of the Solution files

There is probably a better way to do this but I know solutions are copied into the Binaries directory right off of the root of the workspace. I can use the built in workspace variable to find its location and append the string literal "Binaries\SolutionName.wsp" to the end.

If you don't already, open up the Build Process Template (workflow designer) we created earlier and get the properties for the Execute Deployment Script action. Change the Arguments property value to be:
String.Format(" ""& '{0}' {1} '{2}\Binaries\{3}'"" ", DeploymentScriptFilename, SolutionName, BuildDirectory, SolutionName)

We are using the String.Format function to call our script {0}, pass in the solution name {1}, and finally concatenate the Build directory with the string literal "\Binaries\" and our solution name to get the full path to our solution file. It is that simple!

Go ahead and queue up another build with the Logging Verbosity set to detailed
clip_image015[1]

I've used this process with a few modifications to execute multiple scripts which can be stored in a string[] Attribute. Here is a screenshot of the multiple deployment log.
clip_image023

Tags:

ALM | SharePoint 2010 | TFS

Deploy SharePoint 2010 Solutions (WSP) files from Team Foundation Server 2010 Build Part 1

by Luke 27. May 2011 05:58

This article is a two part series which will explain how to Configure Team Build 2010 to Build a SharePoint Solution package and then deploy the solution package to a SharePoint server. In this scenario the build agent is running SharePoint Foundation 2010.

Step 1: Prepare the Build Machine

There are lots of good articles on MSDN which cover the basics of setting up a Build Environment. Once you are done preparing, the best pen test I have come across is to login to the build machine (as the build service account) and set it up exactly like you were going to develop on it. For instance, you would want to install:

  • · SharePoint Foundation 2010 – or SharePoint Server 2010, whatever your shop is developing against
  • · Visual Studio 2010 + Extensions for SharePoint Products
  • · Any additional 3rd party libraries you use like NUnit
  • · Grab the latest solutions and project files from Team Foundation’s Source Control
  • · Configure the project to deploy to the server and try to deploy your solution
  • · If everything builds, you are ready to proceed with deployment automation

Rather than re-create the content for creating a custom build I would recommend you take a look at this series of posts from Ewald Hofman. He put together some great information on customizing the Team Build process. I HEAVILY relied on his tutorials to get the build process going. You can either read his posts, specifically Part 1, Part 2, and Part 14. Or, I am going to attempt to summarize the necessary steps below. Now that the build machine is ready, let's move to the next setup.

Step 2: Wire Up a Basic Build

First we should make sure the build works. Navigate to Team Explorer and right-click on the Builds node for your project: choose New Build Definition…
clip_image001

Name it Build SharePoint, click on the Build Defaults section. Choose your Build Controller from the dropdown and put in the UNC path for where the built files will be placed. Leave the defaults for Triggers. If you don’t already have a workspace setup, then configure the locations for the projects you are going to build.

Click on the Process tab.
clip_image002

Verify the correct solution or project is selected in the Items to Build field. clip_image003 Go ahead and Save the Build and queue up a new build. It should output the assemblies for your project/solution into the drop folder.
clip_image004

Once the build finishes go ahead and double click the build to see the entire overview. Click the Open Drop Folder to view the output of the build. You might be asking, "Where is the Solution file?." That is our next task.
clip_image005

Step 3: Get a Solution Package

Right-click on your BuildSharePoint from Team Explorer and choose Edit Build Definition.
clip_image006

In the Process section, expand the Advanced grouping. Find the MSBuild Arguments field and enter /p:IsPackaging=true. Save the build definition and queue up another build. This time you should have a nice .wsp file in your drop folder.
clip_image008

Tags:

SharePoint 2010 | TFS | ALM

Server Core 2008 and TFS2010

by Luke 10. December 2010 16:02

I’ve been playing with Server Core for Windows Server Enterprise 2008 R2. It has been a wonderful experience. I think Microsoft got this right for virtualization environments. The platform can be setup and configured easily. Once configured, the environment basically maintains itself and you can remotely connect using the Windows 7 Admin pack tools to connect to the Hyper-V manager to manage the VMs.

Part of the server core configuration is to have a TFS 2010 run as a virtual machine on top of the environment. I’ve been considering adding unit testing to a lot of our source control projects as well. NUnit has caught my eye and I’ve been checkign out some research on integrating it into TFS 2010. Found a great project on codeplex called NUnit for Team Build dedicated to integrating NUnit with TFS. Very excited!

Tags:

Server Core | TFS

SharePoint 2010 Picture Library and the Client Object Model

by Luke 4. August 2010 17:18

The goal of a recent project was to provide a way for a non-technical person to be able to add images and metadata to an ASP.NET page without the intervention of a developer.  I’m using SharePoint Foundation 2010 as the “user-friendly” interface where anyone with the right permissions can upload an image and add some metadata. And accessing the Picture Library using the new SharePoint 2010 Client Object Model (ClientOM).

I first started by writing a simple .aspx page to retrieve the images from SharePoint. In order for this to work I had to enable anonymous access to the document library. I used the MSDN examples as a starting point. In order for the below to work, you will need to add a reference to Microsoft.SharePoint.Client.dll and the Microsoft.SharePoint.Client.Runtime.dll. Below is what I used to retrieve the necessary list item collection. Ignore the parameters  in the CAML query, I’ll explain those last:

using (ClientContext clientContext = new ClientContext(url + "/sites/siteName/"))
{
      // gets the credentials of the web application
      clientContext.Credentials = System.Net.CredentialCache.DefaultCredentials;

      List oList = clientContext.Web.Lists.GetByTitle("listTitle");
      StringBuilder query = new StringBuilder();
      query.Append("<View>")
           .Append("<Query>")
           .Append("  <Where>")
           .Append("  </Where>")
           .Append("  <OrderBy>")
           .Append("    <FieldRef Name='" + OrderColumn
                   + "' Ascending='" + Ascending.ToString() + "' />")
           .Append("  </OrderBy>")
           .Append("</Query>")
           .Append("<RowLimit>" + RowLimit)
           .Append("</RowLimit>")
           .Append("</View>");
      CamlQuery camlQuery = new CamlQuery();
      camlQuery.ViewXml = query.ToString();

      Microsoft.SharePoint.Client.ListItemCollection items =
        oList.GetItems(camlQuery);

      // load server data and required columns
      clientContext.Load(
        items,
        listItems => listItems.Include(
          item => item.File,
          item => item.Id,
          item => item["Title"],
          item => item["Description"],
          item => item["ImageCreateDate"],
          item => item["votes"]));

      clientContext.ExecuteQuery();
}

 

The trick to making this code efficient is to only request the columns you need data from. I have used the .Include() statement to only retrieve the necessary columns.

Once I had my ListItemCollection, it was easy to iterate the items in the collection and write some HTML out onto the page.  The foreach takes advantage of SharePoint’s auto-generated thumbnails and displays them on the page. The full sized image is accessed via JavaScript using a LightBox type presentation.

In my first attempt I was “guessing” as to how big the thumbnails should be. But a co-worker pointed out to me SharePoint auto-generated its own thumbnails! So, after doing some simple research I determined that every time an image was uploaded to a picture library it used a consistent algorithm to generate the thumbnail. By adding a ‘/_t/’ to the URL then replacing the last . (period) with an _ (underscore) and appending “.jpg” to the end of the image URL, I could grab the auto-generated thumbnails, wicked cool!

// iterate each list item and generate HTML
foreach (Microsoft.SharePoint.Client.ListItem listItem in items)
{
  // images accessed via SP Library, library must allow anonymous read on items
  string imageUrl = url + listItem.File.ServerRelativeUrl;
  string thumbUrl = imageUrl.Substring(0, imageUrl.LastIndexOf('/'));
  thumbUrl = thumbUrl + "/_t/" + listItem.File.Name.Replace('.', '_') + ".jpg";
  DateTime taken = (listItem["ImageCreateDate"]) != null ?
     DateTime.Parse(listItem["ImageCreateDate"].ToString()) : DateTime.Now;

  // sanatize data from SharePoint
  string title = (listItem["Title"] != null) ? listItem["Title"].ToString() : "No Title";
  string description = (listItem["Description"] != null) ? listItem["Description"].ToString() : "";
  int itemId = listItem.Id;

  StringBuilder sb = new StringBuilder();
  sb.Append("<div class='picItem'>");
  sb.Append("  <div class='picItemImage'>");
  sb.Append("    <a title='" + description + "' href='" + imageUrl + "' rel='lightbox[" + ThumbnailGroup + "]' />");
  sb.Append("      <img src='" + thumbUrl + "' alt='" + title + "' />");
  sb.Append("    </a>");
  sb.Append("  </div>");
  sb.Append("  <p>" + taken.ToShortDateString() + " - " + title + " </p>");
  sb.Append("</div>");

  imagePane.Controls.Add(new LiteralControl(sb.ToString()));
}

The last piece of functionality I added to the project was wrapping everything up into a user control and adding Properties to the user control. I used the properties in two places: 1. Parameters to be passed into the CAML query to change the sort order, and sort column values of the returned ListItemCollection and 2. as configurable thumbnail group names so if the control is re-used on the page the images can be grouped together or separated.

public int RowLimit { get; set; }
public string OrderColumn { get; set; }
public bool Ascending { get; set; }
public string ThumbnailGroup { get; set; }

To keep things simple, all my code executes in the Page_Load() method. And, because I have the ListItem’s ID, I can manipulate the SharePoint list item. But that is for another post.

Let me know what you think? Any improvements or suggestions? For instance, how can I eliminate the need for anonymous access on the Picture Library and just display the images from memory?

Tags: , ,

ClientOM | SharePoint 2010

About Luke

C# .NET developer who really likes kettle style potato chips. Current favorite is Cape Code potato chips with a Henry Weinhards root beer on the side, mmmm delicious

 
 
The views and opinions on this blog site are my own and are not that of my employer.