Blogging with BlogEngine.Net

25. February 2009

I found a few simple applications that make blogging in BlogEngine.Net very easy and convenient. Hopefully you will as well.

Windows Live Writer
http://get.live.com/writer/overview
I didn’t know Live had a blogging application let alone one that will automatically connect to my Blog for me to post on. This application makes things very easy as I prefer desktop applications over web applications.

Paste From Visual Studio
http://gallery.live.com/liveItemDetail.aspx?li=d8835a5e-28da-4242-82eb-e1a006b083b9&l=8
This little number is my replacement to CodeToHtml plugin I used on VOX. It is a plugin for Windows Live Writer that can paste in things from your Visual Studio clipboard and keep them formatted nicely for your blog. Plus, it is a plugin for Live Writer and not visual studio keeping things on the development end nice and tidy.

Happy Coding :)



Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Visual Studio, BlogEngine.Net

Reading Excel with C#

25. February 2009

Overview

This article explains how to read Excel documents with C#. After two or three projects dealing with copying and pasting data from sql server to excel, I decided that it would be a good time to write some code to help with the process. Here is the basic code for reading an excel spreadsheet.

Code

// Create the connection string
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
    location + @";Extended Properties=""Excel 8.0;HDR=YES;""";

// Create a factory
DbProviderFactory factory =
       DbProviderFactories.GetFactory("System.Data.OleDb");

// Create an adapter
DbDataAdapter adapter = factory.CreateDataAdapter();

// Create a select command to get the dataset
DbCommand selectCommand = factory.CreateCommand();
selectCommand.CommandText = "SELECT * FROM [" + sheetName + "$]";

// Set up the connection and the connection string
DbConnection connection = factory.CreateConnection();
connection.ConnectionString = connectionString;
selectCommand.Connection = connection;

// Set up the command
adapter.SelectCommand = selectCommand;

// Create the dataset
DataSet ds = new DataSet();

// Load the results
adapter.Fill(ds);

return ds;
Basically, I am just passing in a location of the document and the sheet name for the particular excel spreadsheet. OLEDB supports Outlook so bringing it into a dataset isn’t that much work. I realize that the article is relatively slim, but I hope it gets viewers pointed in the right direction. Thank you Dave Hayden for my step.

Happy Coding



Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Excel, C#

Automating builds and publishing with CruiseControl.Net

24. February 2009

Overview 

A lot of people like the idea of continuous integration within their company. I have found it to be necessary for more than just testing builds on check-in. My primary use for it is publishing builds to servers and deployment. This article explains how to set up CruiseControl.Net with an Asp.Net solution and two projects. One verifying builds and automatically building on check-in; the second which requires the build to be forced and publishes the application to a server.

Installation

We need a few things on the build server to start out. Download the tools below if you don't have them.

* CruiseControl.Net - http://sourceforge.net/projects/ccnet/ 
* NAnt - http://sourceforge.net/project/showfiles.php?group_id=31650&package_id=23704
* Web Deployment Project – Download Here

Note: My particular configuration has .Net Framework 3.5 as well as some other build specific applications. Verify that you have all of the software required for command line builds installed on your integration server.

Run the CruiseControl.Net installer as well as the NAnt installer.

Configuration

Once both installers are done, find the location where you installed CruiseControl.Net and open up the ccnet.config file. Here is a good start for a configuration.

<cruisecontrol xmlns:cb="urn:ccnet.config.builder">
    
<!-- Basic project to verify build on every checkin -->
<project name="(Build) MyProject" queue="MyProjectQueue" queuePriority="1">
    <workingDirectory>C:\ccnet\projects\MyProject\work</workingDirectory>
    <artifactDirectory>C:\ccnet\projects\MyProjectBuild\artifact</artifactDirectory>
    
    <sourcecontrol type="svn">
        <executable>C:\Program Files\SlikSvn\bin\svn.exe</executable>
        <trunkUrl>svn://pathToSvnRepo/MyProject/trunk</trunkUrl>
        <username>SubversionUser</username>
        <password>Password</password>
    </sourcecontrol>
    
    <tasks>
        <msbuild>
            <executable>C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe</executable>
            <projectFile>MyProject.sln</projectFile>
            <buildArgs>/p:Configuration=Debug</buildArgs>
            <targets>Clean;Build</targets>
            <logger>C:\ccnet\server\ThoughtWorks.CruiseControl.MSBuild.dll</logger>
        </msbuild>
    </tasks>
</project>

<!-- Publish project using web depoloyment and move to server -->
<project name="(Publish) MyProject" queue="MyProjectQueue" queuePriority="2">
    <workingDirectory>C:\ccnet\projects\MyProject\work</workingDirectory>
    <artifactDirectory>C:\ccnet\projects\MyProjectPublish\artifact</artifactDirectory>
    
    <triggers />

    <sourcecontrol type="svn">
        <executable>C:\Program Files\SlikSvn\bin\svn.exe</executable>
        <trunkUrl>svn://pathToSvnRepo/MyProject/trunk</trunkUrl>
        <username>SubversionUser</username>
        <password>Password</password>
    </sourcecontrol>

    <tasks>
        <msbuild>
            <executable>C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe</executable>
            <projectFile>MyProject.sln</projectFile>
            <buildArgs>/p:Configuration=Release</buildArgs>
            <targets>Clean;Build</targets>
            <logger>C:\ccnet\server\ThoughtWorks.CruiseControl.MSBuild.dll</logger>
        </msbuild>
        <msbuild>
            <executable>C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe</executable>
            <projectFile>MyProject.Deployment.wdproj</projectFile>
            <buildArgs>/p:Configuration=Release</buildArgs>
            <logger>C:\ccnet\server\ThoughtWorks.CruiseControl.MSBuild.dll</logger>
        </msbuild>
        <nant>
            <executable>C:\nant-0.86-beta1\bin\nant.exe</executable>
            <nologo>true</nologo>
            <buildFile>C:\ccnet\projects\antscripts\Publish.build</buildFile>
            <buildArgs>-D:sourceDir=C:\Inetpub\MyProject -D:targetDir=PathToServer</buildArgs>
            <logger>NAnt.Core.XmlLogger</logger>
        </nant>
    </tasks>
</project>
    
</cruisecontrol>

Here is the rundown. The first project pulls the source down and builds it automatically whenever it detects a commit to the subversion server. This allows you to see whenever a build is broken. The second project is pretty cool. The <triggers /> tag says that this build must be forced. It pulls from the same repository, except it builds for release. It then runs the web deployment project which changes the web.config to be configured for release. The build is published, and the ant script moves the publish from local IIS to the hosting server.

A few notes. Notice the queuePriority tag? Since both projects use the same source control, I put them in a queue so they don’t try to build off of the same folder at the same time. Also, it is worth looking into the web deployment project. It allows you to configure different application settings for different build types.

As for the ant script? Here you go:

<?xml version="1.0"?>
<project name="Publish to server" default="publish-to-server">
    <target name="publish-to-server">
        <echo message="Connecting with server" />
        <exec program="net.exe" 
                    commandline="use \\server\location /user:un pw" />
        
        <echo message="Publish ${sourceDir} to ${targetDir}" />
        <delete dir="${targetDir}" />
        <mkdir dir="${targetDir}" />

        <move todir="${targetDir}">
            <fileset basedir="${sourceDir}">
                <include name="**" />
            </fileset>
        </move>
    </target>
</project>

This is assuming that you have network access to your server. If you need to do ftp or something of the like, you should look into ftp with ant scripts. Basically this script connects to the server, removes the current directory, and copies over the publish information.

Thanks to Joe Lombrozo for figuring out the ant script.



Currently rated 3.0 by 1 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5