Wednesday, November 23, 2011

Parsing XML and databinding using jsRender and jsViews (RIP jQuery Templates)

I have always been a huge fan of the very flexible ASP.NET ListView control for creating templates and databinding nested data collections. Recently though I have been making a stronger effort to work with client side technologies like jQuery and client friendly data formats like JSON and JSONP. Thanks to the hard work of Microsoft’s Boris Moore, a new technology called jQuery Templates was put into beta as an official plugin and a CDN was created in jQuery and Microsoft. Unfortunately after spending some time studying the framework, I learned that it had been deprecated, “rebranded” as jsRender and jsViews, and a tentative schedule to add it to the jQuery UI framework (at least the jsRender portion). Fortunately, the new framework still has support, has improved performance, and a syntax that hasn’t changed too much. This is really a useful technology, so hopefully it will get adopted soon as a first class jQuery plugin or independent framework.
jsRender Databinding SyntaxThe first line initializes the template object. The object is then rendered with the data and appended to an html element.
$("#tblTemplate").template("tblTemplate");
$("#tblBod").append($.render(obj, "tblTemplate"));

Saturday, September 17, 2011

Installing SharePoint 2010 on Windows 8

Just for kicks I got Windows 8 Preview installed today and thought I'd see if I could get SharePoint 2010 installed as well. Fortunately, the setup instructions are pretty much identical to the ones used for Windows 7. The important thing to remember is that you need to make sure IIS uses .NET 2.0 instead of 4.0.
  • Install SQL Server 2008. I used R2, but you can use any version listed in the requirements.
  • Ensure all of the required IIS features are installed through Programs and Features. The easiest way to do this is to use the script that Microsoft provides. You can do this by copying the following into a Command Prompt.

Monday, June 6, 2011

Add every installed web part to a single SharePoint page

Here is a code snippet that won't be used for normal day usage, but something is very helpful for testing web part UI and branding. This could also be used for performance benchmarking and exploring or demonstrating different web parts in a development environment. By default, the code will alphabetize the web parts by title and then adds them to the top web part zone.You can easily update the code to filter out specific web parts, update web part properties, populate specific web part zones.

InstructionsThe first thing you’ll want to do is increase the maximum web parts per zone. The default is set to 50, but you can increase it by editing your web.config.

Friday, June 3, 2011

Create a favorites icon (favicon) for your SharePoint 2010 site

With SharePoint 2010, Microsoft has provided a new control called SPShortcutIcon. Sadly, if you are trying to use this within a feature deployment and would like to use relative paths using $SPUrl variables, you will run into some issues. This is because the SPShortcut.IconUrl is of type URI and the $SPUrl variable cannot be cast properly. Fortunately, there is a work around. It’s a bit ugly, but instead of using the control, you can use Literal controls to render the proper html link control.
SPShortcut usage– This is hardcoded, so won’t work with feature deployments.
<SharePoint:SPShortcutIcon runat="server" IconUrl="/Style Library/Waffles/favicon.ico"/>
SPShortcut usage with $SPUrl – This will result in the following error: Unable to cast object of type 'System.String' to type 'System.Uri'.
<
SharePoint:SPShortcutIcon runat="server" IconUrl="<% $SPUrl:~sitecollection/Style Library/Acme/favicon.ico %>" />
Solution


<
asp:Literal runat="server" Text="&lt;link rel='shortcut icon' href='" /><asp:Literal runat="server" Text="<% $SPUrl:~sitecollection/Style Library/Acme/favicon.ico %>" /><asp:Literal runat="server" Text="' type='image/vnd.microsoft.icon' /&gt;" />
Google.com’s favorite icon

image
SharePoint 2010, Favorites Icons (FavIcons) and SPUrl (SPUrlExpressionBuilder)Credit goes to Joel for this tip. Unfortunately, I could only get to his post via Google cache.http://joelblogs.co.uk/2010/11/09/sharepoint-2010-favorites-icons-favicons-and-spurl-spurlexpressionbuilder/

Wednesday, June 1, 2011

Get SharePoint audit details across the farm for specific users

This code snippet gets all audit details for specific users across an entire SharePoint 2007/2010 farm and saves them to a CSV file. I have also added a method to include a file extension column. This comes in handy as you will likely want to filter out web extensions like aspx, html, css, etc., picture formats, and folders. In order to get any data, auditing will have to have been enabled at the Site Collection level through site settings or programmatically at the item level. Keep in mind that this will take some time if your AuditData tables are very large, so in this case you will want to make further refinements by filtering by site collection, list, or list item. Site collections can be filtered out by tweaking the loop statements below, while you can filter out list or list items by updating the RestrictToList or RestrictToListItem methods of the SPAuditQuery object.
Helpful Links
Configure audit settings for a site collections
http://office.microsoft.com/en-us/sharepoint-server-help/configure-audit-settings-for-a-site-collection-HA010099726.aspx
Custom Auditing in SharePoint
http://msdn.microsoft.com/en-us/magazine/cc794261.aspx

Instructions
Create a c# Console Application in Visual Studio, add a reference to Microsoft.SharePoint, and then add the following code to Program.cs. This will work with SharePoint 2007 and 2010 as long as you reference the correct assembly. Don’t forget to make sure your Visual Studio project’s Platform Target is Any CPU or x64.

Wednesday, May 25, 2011

Determine auditing configuration details for all of your SharePoint site collections

I recently had a customer whose SharePoint audit tables had getting very large. They wanted to know which site collections had auditing enabled so they could meet with their end users to determine if auditing was really necessary. Here is a code snippet for finding out which SharePoint sites have auditing enabled. The code will loop through all site collections in the farm and then create a CSV file with auditing configuration details.
InstructionsCreate a c# Console Application in Visual Studio, add a reference to Microsoft.SharePoint, and then add the following code to Program.cs. This will work with SharePoint 2007 and 2010 as long as you reference the correct assembly. Don’t forget to make sure your Visual Studio project’s Platform Target is Any CPU or x64.


Wednesday, April 13, 2011

Create Rounded Corners And Gradient Images On The Fly!

I am often tasked with taking a mockup and branding a site. This usually involves a custom master page with tweaks to the CSS for the layout and color scheme. It also involves the creation of images used to compliment the UI, the holy grail for some being gradient images and rounded corners. For the amateur graphic designer like myself, this often becomes a tedious task that involves repetitive tweaks to an image. I once had a client tell me that I had the wrong shade of “pumpkin”. (Depending on your disposition, this could result in an act of either running full speed into a brick wall or rocking yourself to sleep every night.)
Enter the poorly named Web Designer Tool! After some experimentation with the System.Drawing and System.Drawing.Drawing2D .NET 2.0 classes, I figured out a way to generate these images on the fly. Now I can rapidly create rounded corners and gradients and don't have to sweat it if a client needs a color or hue adjusted. The rounded corners include many options, including width, height, gradient and solid colors, radius corner size, and border. I also provide a preview feature that integrates the images into a sample html page and launches it in your default browser. I have successfully tested this in IE 6.0 ~ 8.0, Chrome 10.0, and Firefox 4.0.
Note: Although this will fly in the face of CSS purists, I have decided to use a simple table based layout for the preview html. I do make an effort to use DIV based layouts for web design, but in this case I have yet to find approach that works flawlessly across browsers types and versions or that integrates nicely with SharePoint. If you are that CSS guru, I welcome you to take these images and come up with a better approach. If you are successful, I would love to try out your code. You are also welcome to use my Shapes.cs class below and build your own tool. Life will be much easier once CSS 3 has reached enough market penetration and we can simply use the border-radius property.