Compare Excel, Word and PDF Files in SharePoint

Now I want to show, how you can compare Office documents stored in SharePoint. Sometimes you need to see the differences of two documents that maybe having the same name and are on two different places in SharePoint. Or if version control is enabled on your site and you want to see what recently has been changed in your document.

How Office Documents can be compared?

I’m using WinMerge in combination with xdocdiff Plugin. I have already written something about the topic in my previous post:

http://bernhardelbl.wordpress.com/2012/04/05/compare-excel-word-and-pdf-files-in-visual-studio-team-foundation-server-2010/

Please, read this before you continue here. Especially capter 1 and 2 are important.

Using WinMerge with SharePoint

It is not possible to insert an url in WinMerge to compare documents directly. Of course you can compare the documents in WinMerge by downloading the files to your local machine and compare them using WinMerge manually.

Saving the files locally and comparing them is a time consuming task. If you need that just a few times in the year, the procedure is ok. If you want to do this more often, you can use my tool.

Sharepoint File Compare – The Tool

The tool can compare Office documents in SharePoint more comfortable.

Features:

  • Enter the url directly into the UI
  • Displays the versions of the SharePoint file
  • Enables you to select a version by double-click on the grid
  • Downloads the files and opens WinMerge to compare them automatically

Software Requirements:

How to use the Tool

The tool is just a single dialog where you can enter the files you want to compare.

1. Download Sharepoint File Compare

You can download Sharepoint File Compare from here…

http://dl.dropbox.com/u/40751518/CodeSamples/SharepointFileCompare-0.8.zip

2. Start Sharepoint File Compare

The first time you need to choose the location of WinMergeU.exe. The default location of WinMerge is:
"C:\Program Files\WinMerge\WinMergeU.exe"
You can change the path to WinMergeU.exe every time later. On the bottom right of the main window you will find this button.

3. Comparing two Files

3.1 Insert the Left

First you should enter the first SharePoint url to the Left text box. Version history is loaded automatically and shown in the grid.

3.2 Select the Right from Version History

Double-click on a version history item will select use the item for Right text box.

3.2 Insert the Right

You do not need the version history, you can add every file url manually in the Right text box.

3.4 Click Compare

Downloads the files locally and opens WinMerge.

Interesting Notes for Developers

The source code is included in the download above. It contains very interesting things for starters and advanced developers.

  • Web Service Authentication using NetworkCredential done with background threading and synchronization.
  • CredUIPromptForWindowsCredentials pinvoke sample to show the windows built-in security dialog
  • A very basic MVVM implementation without using a framework
  • Anchor and docking using WPF
  • Asynchronous operations with multi-threading using System.Threading.Tasks namespace and an very interesting (background) Activity class implementation that simplifies background threading and synchronization in WPF.
  • SharePoint Web Services usage is shown: Webs.asmx, Versions.asmx

Maybe for some of this points I will write another blog posts from a more technical perspective.

Create a Non-Expiring Test Certificate (pfx) for ClickOnce Applications

A ClickOnce application must be signed using a certificate. You can buy a real certificate or create a Test Certificate by your own. Visual Studio 2010 helps in creating such a Test Certificate. It offers a wizard and is very easy to use. The draw-back of the simple feature is that you can not do customization.

Create a Test Certificate in Visual Studio

Disadvantages of Visual Studio Test Certificate

If you want to deploy your application with such a Test Certificate you need to consider the following disadvantages:

  • “Issued To” and “Issued By” will contain the user name of your current windows account
  • “Expiration Date” is set to “Expires in one year”

Create a more customized Test Certificate (pfx)

If you want to create a more customized Test Certificate, you can do that by using the following script.

makecert -sv ClickOnceTestApp.pvk
         -n CN=Sample ClickOnceTestApp.cer
         -b 01/01/2012 -e 12/31/2100 -r
pvk2pfx -pvk "ClickOnceTestApp.pvk"
        -spc "ClickOnceTestApp.cer"
        -pfx "ClickOnceTestApp.pfx"

To learn more about the used tools
Makecert
http://msdn.microsoft.com/en-us/library/bfsktky3%28v=vs.80%29.aspx

Pvk2Pfx
http://msdn.microsoft.com/en-us/library/windows/hardware/ff550672%28v=vs.85%29.aspx

Add your Test Certificate to your Visual Studio Project

If you add your custom Test Certificate to your Visual Studio Project it will look like this.

Download the Script Sample

http://dl.dropbox.com/u/40751518/CodeSamples/MakeCert.zip

Sheet Switch AddIn for Excel 2010 – Switch between a lot of Sheets

Office 2010 Only – Please note that the solution here works only with Office 2010

Last year I worked in a specification team for a few month and did a lot in Office Word and Excel. We had one Excel File that contained about 100 Sheets. Switching between the sheets was a very time consuming task. Excel does not offer a comfortable way to navigate, when not all Sheets can be displayed in the navigation bar on the bottom of the Excel window.

Let’s come to look closer, what I mean

Only 5 Sheets are visibile all others are hidden. You must scroll to reach them.

Right-Click to the Sheet-Scrollbar shows the following screen

Using this feature you can switch between the first 15 sheets. This way is acceptable, if you don’t have more that 15 Sheets in your Workbook. Let’s take a more closer look to the “More Sheets…” Option here.

You can see only 12 Sheets by default. To reach more you need to scroll down. The dialog is not realizable. This feature totally useless.

As you can see Excel does not provide a way to switch comfortable between more that 15 Sheets in a Workbook. So I decided to create my own solution.

Excel Sheet Switch

The Add In displays a multi-line switch bar on the bottom of the Excel application’s window, if the Workbook contains more that 5 Sheets.

Download Setup and Source

Office 2010 Only – Please note that the solution here works only with Office 2010

http://dl.dropbox.com/u/40751518/CodeSamples/Be.ExcelSheetSwitch-1.0.0.4.zip

Install the AddIn using Setup

You can use the setup.exe included in the download. Please ignore the security warning and click install – I’m using a Test Certificate there.

Technical Solution

I used Visual Studio 2010 to create a VSTO solution. It tooks me 15 minutes to write the code needed. It’s very simple, so I don’t want to go into details. If you want to know more, you can discover the code in the download above.

HOWTO: Detect design mode in WPF, ASP .NET and Windows Forms applications

If you want to detect the design mode in code, I’m using the following method, that is working fine for WPF, ASP .NET and Windows Forms applications. It’s easy, stable, bug free and has a very good performance.

static class Util
{
    /// <summary>
    /// Contains true, if we are in design mode of Visual Studio
    /// </summary>
    private static bool _designMode;

    /// <summary>
    /// Initializes an instance of Util class
    /// </summary>
    static Util()
    {
        // design mode is true if host process is: Visual Studio, Visual Studio Express Versions (C#, VB, C++) or SharpDevelop
        var designerHosts = new List<string>() { "devenv", "vcsexpress", "vbexpress", "vcexpress", "sharpdevelop" };
        var processName = System.Diagnostics.Process.GetCurrentProcess().ProcessName.ToLower();
        _designMode = designerHosts.Contains(processName);
    }

    /// <summary>
    /// Gets true, if we are in design mode of Visual Studio etc..
    /// </summary>
    public static bool DesignMode
    {
        get
        {
            return _designMode;
        }
    }
}

I always had troubles by using the built-in methods of .NET Framework like the System.ComponentModel.Component.DesignMode property. For ASP.NET and WPF there exist other methods to determine the design mode. For me the above one replaces all others and works like a charm.

RibbonGenerator for Visual Studio 2010 Express Editions: Windows Ribbon for WinForms

Yes, RibbonGenerator is also working with Express Editions of Visual Studio 2010, but in version 2.6 of the Ribbon library you need some extra effort to bring the tool up to work.

Requirements:

  • Windows 7 SDK
  • Visual  C++ 2010 Express
  • Visual C# or Basic 2010 Express

Note: You must have Visual C++ 2010 Express Edition installed because it contains the link.exe file that is need to generate .ribbon files.

Manual Registration of Custom Tool

Because the RibbonGenerator setup is not included in compiled format and because the Express Editions does not support setup projects, it is necessary to register the custom tool manually.

  1. Start the “.\RibbonLib_v2.6\RibbonGenerator\RibbonGenerator.sln” solution and ignore all errors
  2. Compile it
  3. Install the RibbonGenerator.dll into the GAC using gacutil.exe in Visual Studio 2010 Command Prompt (Run as Administrator)
    gacutil – i RibbonGenerator.dll
  4. Register the custom tool in Express Edition of Visual Studio 2010. The simplest way is to modify the existing .reg in the RibbonGenerator source folder. Choose the x64 reg file if you have a 64bit operating system. .\RibbonGenerator\RegisterCustomTool_VS2010.reg
    .\RibbonGenerator\RegisterCustomTool_VS2010_x64.reg
    Let take a look into the second one
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\CLSID\{B64582D9-A489-42F4-BA55-BB6039D82916}]
@="RibbonGenerator"
"InprocServer32"="C:\\WINDOWS\\system32\\mscoree.dll"
"Class"="RibbonGenerator.CustomTool"
"Assembly"="RibbonGenerator, Version=1.0.1.0, Culture=neutral, PublicKeyToken=3cf107c5d7e68b1c"
"ThreadingModel"="Both"

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\Generators\{164B10B9-B200-11D0-8C61-00A0C91E29D5}\RibbonGenerator]
@="Ribbon Generator"
"CLSID"="{B64582D9-A489-42F4-BA55-BB6039D82916}"
"GeneratesDesignTimeSource"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\Generators\{E6FDF8B0-F3D1-11D4-8576-0002A516ECE8}\RibbonGenerator]
@="Ribbon Generator"
"CLSID"="{B64582D9-A489-42F4-BA55-BB6039D82916}"
"GeneratesDesignTimeSource"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\Generators\{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}\RibbonGenerator]
@="Ribbon Generator"
"CLSID"="{B64582D9-A489-42F4-BA55-BB6039D82916}"
"GeneratesDesignTimeSource"=dword:00000001

All we have to do now, is to place the correct keys for Express Editions

For Visual Studio 2010 (64bit Operating System)

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0

For Visual C# 2010 Express (64bit Operating System)

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VCSExpress\10.0

For Visual Basic 2010 Express (64bit Operating System)

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VBExpress\10.0

RibbonGenerator Details: Windows Ribbon for WinForms

Let take a look into the details of RibbonGenerator of Windows Ribbon for WinForms

What is RibbonGenerator doing?
It generates .ribbon files that contains the definition of the commands and controls and can be used to display a Ribbon control on a Windows Form.

What type of application is RibbonGenerator?
There two applications available that can be used to generate .ribbon files.

  • A custom tool that can be used directly inside Visual Studio and
  • A console application that can be used from command line

Both application are having the same functionality.

How is RibbonGenerator generating .ribbon files?
Because there is no API available, the tool is “just” executing a .bat file. It is a custom .bat file. The content is created by the tool. After the first invocation the “template.bat” is placed in the following folder:
C:\Users\<username>\AppData\Local\RibbonGenerator
You can customize it. When you delete it, it will be recreated after the next invocation of RibbonGenerator.

What does this .bat file doing?
Let take a look into the template.bat file.

"C:\Program Files\Microsoft SDKs\Windows\v7.0\bin\UICC.exe" "{XmlFilename}" "{BmlFilename}" /res:"{RcFilename}"
"C:\Program Files\Microsoft SDKs\Windows\v7.0\bin\rc.exe" /v "{RcFilename}"
cmd /c "("%VS100COMNTOOLS%..\..\VC\bin\vcvars32.bat") && ("%VS100COMNTOOLS%..\..\VC\bin\link.exe" /VERBOSE /NOENTRY /DLL /OUT:"{DllFilename}" "{ResFilename}")"
  1. UICC.exe (available in Windows 7 SDK) is executed to generate a resource definition script file of the Ribbon XAML
  2. rc.exe (available in Windows 7 SDK) is executed to generate a .res file – a windows resource file
  3. link.exe (available in Visual Studio 2010 or Visual C++ 2010 Express)) is executed to generate an unmanaged .dll file. This file is the .ribbon file that can be used by Ribbon control!

The placeholder in there beginning with an “{” are all replaced by the tool. All files that are created will be deleted at the end of the generation process. Only the .ribbon file ({ResFilename} will not be deleted.

Quickstart Tutorial: Windows Ribbon for WinForms

Here I will show you how you can start using the Windows Ribbon from CodePlex.

Prepare your developer machine

Installation of Windows 7 SDK is required to create and modify the ribbon on a developer machine.

1. Download latest version of RibbonLib from CodePlex

You can find the library here: http://windowsribbon.codeplex.com/

2. Build the RibbonGenerator setup and install it.

Start the Visual Studio 2010 Solution of RibbonGenerator, set the build configuration to Release and build it twice!
After the second build it will compile without errors! This is an official Visual Studio 2010 bug and we have to live with it.

.\RibbonLib_v2.6\RibbonGenerator\RibbonGenerator.sln

Now you can install the new setup file that you will find here…

.\RibbonLib_v2.6\RibbonGenerator\RibbonGenerator.Setup\Release\RibbonGenerator.Setup.msi

3. Compile a Ribbon.dll

To get a compiled version of Ribbon.dll start the sample solution and build it using Visual Studio

.\RibbonLib_v2.6\Ribbon-cs.sln

4. Create a new Windows Forms application containing the Ribbon Control.

Add the Ribbon to your Toolbox doing a right-click on Toolbox / Choose Items
.\RibbonLib_v2.6\Ribbon\bin\Release\Ribbon.dll

Drag/Drop the Ribbon to your form

For your body you can add a Panel control and set the DockStyle property to Fill

Add a new Xml file to your Project and rename to Ribbon.xml

Add the following content to the file.

<?xml version='1.0' encoding='utf-8'?>
<Application xmlns='http://schemas.microsoft.com/windows/2009/Ribbon'>
	<Application.Commands>
	</Application.Commands>

	<Application.Views>

		<Ribbon>
		</Ribbon>
	</Application.Views>
</Application>

Set the CustomTool of the Ribbon.xml in the File Properties to RibbonGenerator to generate a .ribbon file.

Now you need to specify the .ribbon file in the Ribbon control properties on your form. The name must be the full name including the namespace.

That’s all. So have a lot of fun playing with the samples included in the download package too.

Suppress Warnings for XML comments

Here i will show you, how you can suppress warnings for XML comments after a Visual Studio build.

Background

If you have checked the "XML documentation file" mark in the Visual Studio project settings, a XML file containing all XML comments is created. Additionally you will get a lot of warnings also in designer generated files, because of the missing or wrong XML comments. While sometimes warnings helps us to improve and stabilize our code, getting hundreds of XML comment warnings is just a pain.

Warnings

Missing XML comment for publicly visible type or member …
XML comment on … has a param tag for ‘…’, but there is no parameter by that name
Parameter ‘…’ has no matching param tag in the XML comment for ‘…’ (but other parameters do)

Solution

You can suppress every warning in Visual Studio.

- Right-click the Visual Studio project / Properties / Build Tab

- Insert the following warning numbers in the "Suppress warnings": 1591,1572,1571,1573,1587,1570

ASP .NET RequiredFieldValidator in Validation Application Block of Enterprise Library 4.0

The Validation Application Block included in Enterprise Library 4.0 is a really cool block. I firstly tried to find the RequiredFieldValidator equivalent to ASP .NET. The fact is in the VAB there is only a StringLengthValidator which can be used for this task. There is a possibility to bend this validator to act exactly like the ASP .NET RequiredFieldValidator does.

 

Configure a ‘RequiredFieldValidator’ with Validation Application Block

1. Use the Configuration Utility to add a StringLengthValidator and rename it to ‘Required Validator’.

config

2. Configure the StringLengthValidator like in the following way.

properties

 

Remarks

You can add an addtional StringLengthValidator to validate for the max length of the string.

Follow

Get every new post delivered to your Inbox.