SharePoint 2010
[Image via Tihomir Ignatov]

Setting up a SharePoint Development Server

Recently I wanted to start some SharePoint 2010 development, and taking Microsoft’s recommendation that developing for SharePoint be conducted on a machine that already has it installed, I set out to create development-optimized SharePoint environment. One of the greatest tools I came across was the SharePoint 2010 Easy Setup Script. The script is a set ofWindows PowerShell scripts that install and configure all the pre-requisites and products to get you developing for SharePoint in no time. Running these scripts will install evaluation versions of:

  • SharePoint Server 2010 + pre-requisites (Standalone)
  • Visual Studio 2010 Ultimate Edition
  • Silverlight 4 Tools for Visual Studio
  • Expression Studio 4 Ultimate
  • Open XML SDK
  • Visual Studio SDK
  • Visual Studio SharePoint Power Tools
  • Office 2010 Professional Plus
  • SharePoint Designer 2010
  • Visio 2010

After downloading and extracting, the installation files will be installed to C:\SharePoint2010EasySetup by default. The next step is to configure the scripts:

Configuring the Installation Scripts

Navigate to C:\SharePoint2010EasySetup\Labs\EasySetup\Source and locate the config.xml file. This is the file you want to modify. Here you can set up a virtual hard disk to install applications to and comment out any applications that you do notwant installed. In my case I wanted to do a fresh install of a Windows 7 64bit operating system on my local operating system, rather than on a virtual disk (it’s recommended to do a fresh install when installing to your local os). After editing the configuration file you will want to save the configuration file and then execute the run.bat file.

Running the scripts:

In the same directory running the Run.bat file will execute the Windows PowerShell scripts in the correct order.  The scripts will download the evaluation versions of the software, install them and configure them. During this process I was asked to reboot several times.

SharePoint 2010 Development Resources:

If you are completely new to SharePoint development I found some of the following resources helpful:

  • SharePoint Server Virtual Labs: MSDN has some free virtual labs. You can use Hyper V to remote into the remote machine provided by Microsoft, which is preconfigured for you to follow the training labs. While these labs are ready to go and everything is set up for you, I did find the remote connection a little slow.
  • Share Point 2010 Training Videos: Microsoft MSDN has some great SharePoint videos that I found very helpful. The videos also link to corresponding labs for you to try your new skills, as well as provide quizzes to make sure you really understand the material.
  • SharePoint 2010 Books: I have been reading SharePoint master Tom Rizzo’s Professional SharePoint 2010 Development
  • Also, for those interested in Team-Based SP development, MVP Andrew Connell has written a very thorough and cohesive article for MSDN on the subject.http://msdn.microsoft.com/en-us/library/gg512102.aspx

This article and many others like this can be found on my SoftArtisans blog.

Disclaimer: While this article was written before I started working at SoftArtisans, I do work at SoftArtisans now.  Support for SoftArtisans products can be found at http://support.softartisans.com/

So today I tried out a product from SoftArtisans called OfficeWriter specifically the WordWriter feature. You can find a Demo here. I set out to create an application that would allow me to fill in a form and generate mailing labels to be printed. I found out that with SoftArtisans product this was extremely easy.

First I created a Mail Merge template in Microsoft office. You can download a copy of my Label Template if you would like.

Then I wrote the following code:

  protected void generateBtn_Click(object sender, EventArgs e)
        {
            // Variables
            object[] arrValues = { firstNameTxt.Text, lastNameTxt.Text, addressTxt.Text, cityTxt.Text, stateTxt.Text, zipCodeTxt.Text };
            generateLabels(arrValues);

        }

        private void generateLabels(object[] arrValues)
        {
            WordTemplate wt = new WordTemplate();
            wt.Open("C:/labels.doc");
            string[] arrNameFields = { "First_Name", "Last_Name", "Address_Line_1", "City", "State", "ZIP_Code" };

            //Bind Mail Merge Fields with Data
            wt.SetDataSource(arrValues, arrNameFields);

            wt.Process();
            //Save to browser
            wt.Save(Page.Response, "Labels.doc", false);
        }

with the following front end:

When opening the generate document I had the following output:

You can download my solution here, but remember that you need an Office Writer license or you must be using the demo license.

This is something I find myself looking up alot so I decided to put it into a post for easy access, and for anyone else who might be looking for a solution.

using System.Threading;
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        { 

            bool createdNew = true;
            using (Mutex mutex = new Mutex(true, "SignleInstance", out createdNew))
            {
                if (createdNew)
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new Form1());
                }
            }

        }
    }

Download Single Instance Application Source Code

I still don’t get why in Visual Studio in VB.NET one could click make single instance application, but that same feature doesn’t exist in C#? Don’t all .NET languages just get compiled to the CIL in the end?

Alternate Case/Format selection:

Have you ever been asked to update some code from a long time ago only to find that almost every tag is in capital letters?  AGHH!

<HTML>
<HEAD>
<TITLE>My Really Old Site</TITLE>
</HEAD>
<BODY>

<P> Lots of body test </P>
<P> Lots of body test </P>
<P> Lots of body test </P>

<IMG SRC="mypic.jpg" width=351 height=113>

</BODY>
</HTML>

Highlight all that code and press CTRL + K then CTRL + F and you will format all the code. It would then look something like this


<html>
<head>
<title>My Really Old Site</title>
</head>
<body>
<p>
Lots of body test
</p>
<p>
Lots of body test
</p>
<p>
Lots of body test
</p>
<img src="mypic.jpg" width="351" height="113">
</body>
</html>

Granted your code may still be far from perfect, but it is definitely a huge help.

Key Launcher (Like Alt + Tab on Windows)

Are you someone that lives by keyboard shortcuts? I know I am.  Are you familar with Windows Alt + Tab keyboard shortcut and toggling through all active programs? Well a similar feature exists within Visual Studio press Ctrl + Tab and toggle through your active Windows and Files.

Visual Studio Ctrl + Tab

Intellisense

Control + Spacebar will bring up intellisense if you are in code view. Great if you click out by accident or you just want to see what is available in the scope of the code.

Visual Studio Intellisense

Break Points

Have a bunch of break points scattered over a couple of files in a solution. Just want to delete them all and start fresh. Ctrl + Shift + F9 will delete all current break points in a solution. Don’t worry Visual Studio will prompt you with a confirmation first.

Get Visual Studio Professional for free!

Well maybe. If you are a student like myself you can head over to https://www.dreamspark.com/which is run by Microsoft. They offer full versions of some of the newest Microsoft products, like Visual Studio. Why? Because they know we are the future and they think we are an investment. Take them up on the opportunity and get ahead of the competition.

Shortcut key posters:

Microsoft Visual Studio has a bunch of keyboard combinations that can be very helpful, to get a more complete list check out some of the resources Microsoft offers:

Visual Studio Key Reference Posters

Visual C# 2008 Keybinding Reference Poster

Visual Basic 2008 Keybinding Reference Poster

Visual C++ 2008 Keybinding Reference Poster

Visual C# 2005 Keyboard Shortcut Reference Poster

Visual Basic 2005 Keyboard Shortcut Reference Poster

Visual C++ 2005 Keyboard Shortcut Reference Poster

This was a problem I racked my brains over for a while when I first started using SSIS. I found a few possible including using a File System task to copy a “Template” Excel file over the existing on, or generating unique files by appending the date.  I simply wanted to overwrite the existing data just like the Flat File Destination gives you that option.

My workaround was as flows:

Create the Data flow the way you normally would, then go to the Control View Then add two Execute SQL Tasks before your data flow is called so it looks like this

Step 1: Add Execute SQL Task 1 to Control Flow
Step 1: Add Execute SQL Task 1 to Control Flow

Set both Execute SQL Tasks to use the Excel file

Step 2: Set Connection Manager
Step 2: Set Connection Manager

Set your first Execute SQL Task’s SQL Command to drop your table which is also known as the sheet name of your Excel file.

Step 3: Drop Table
Step 3: Drop Table

Repeat step 3 on the second Execute SQL Command this time create your tables.

If you are new to SSIS or looking for some more advanced help, one of my favorite books is Professional Microsoft SQL Server 2012 Integration Services you should check it out.