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.

So in one of my recent projects I had to parse a Flickr feed and extract the image urls the code I came up with is as follows:

<?php
/* Author: Samuel Haddad
 * SimpleXML Flicker Feed Parser
 */
//Feed URL in RSS Format
$url ="http://api.flickr.com/services/feeds/photos_public.gne?lang=en-us&format=rss_200"; //FEED URL

//Use simple XML to parse the feed
$xml = simplexml_load_file($url);
$items = $xml->xpath('/rss/channel/item');
foreach($items as $item){
 $nsmedia = $item->children('http://search.yahoo.com/mrss/');
 $img = $nsmedia->content->attributes();
 echo $img; //URL of Image
 echo "<br/>";
}
?>

Of course my code did more then just extract the URL, but I will leave the rest up to the creative developers.

Recently I was trying to commit to my Jango Desktop project hosted on Google code. I was using AnkhSVN and I kept getting an error similar to:

SharpSvn.SvnRepositoryIOException: Commit failed (details follow): ---> SharpSvn.SvnRepositoryIOException: Server sent unexpected return value (405 Method Not Allowed) in response to MKACTIVITY request for

If anyone else runs into this issue I was trying to commit to the read only repository. An easy way to tell if this is your issue is to look at the repository url. Google’s commit repository starts with https: // not http://

If this is your issue log into Google code to obtain the correct repository url.

I was helping a friend write some VBscript the other day. I was trying to write a simple copy function and I kept getting permission denied. However I was logged in locally as the administrator so that could not be it.

My code looked something like:

Sub CopyFile(source, destination)
	set filesys=CreateObject("Scripting.FileSystemObject")
	If filesys.FileExists(source) Then
	   filesys.CopyFile source, destination
	End If

End Sub

The Solution is: add “\” add the end of any of your path names like
Dim destinationpath
destinationpath = “C:\” & myfolder & “\”

Hope this helps someone else.

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?