Programming

Unhide VeryHidden Excel Worksheets

Here is the macro I use to unhide very hidden worksheets.

Sub Unhide()
Dim ws As Worksheet
For Each ws In Sheets
ws.Visible = True
Next
End Sub

Thursday, November 3rd, 2011 Excel, Programming No Comments

Cannot import the following key file fix

This one has caused me a few hours of pain….a couple of time.  It is about time I document how I fixed it.

The Error:

Cannot import the following key file: <filename>.pfx. The key file may be password protected. To correct this, try to import the certificate again or manually install the certificate to the Strong Name CSP with the following key container name: VS_KEY_ E2AEBF22AB52DD08    <Application Name>

The Fix:

  1. Open Visual Studio Command Prompt (It can be found in the Windows Start menu)
  2. Type sn -i “c:\Pathtofile\<filename>.pfx” TVS_KEY_ E2AEBF22AB52DD08
  3. Reimport the pfx file into Visual Studio

The sn.exe with the –i parameter, installs a key pair from <infile> into a key container named <container>.

Tags: , , , ,

Wednesday, July 27th, 2011 .NET, Development, Programming No Comments

.NET High Quality Thumbnail Generation

This method is a modified version of Mike Borozdin method which I happen to enjoy very much. The biggest changes I made where to add using statements around the disposable objects such as the Bitmap and the Graphics object to avoid memory leaks, as well as a few minor changes.

//Image Resize Helper Method
private static Bitmap ResizeImage(String filename, int maxWidth, int maxHeight)
{
    using (Image originalImage = Image.FromFile(filename))
    {
        //Caluate new Size
        int newWidth = originalImage.Width;
        int newHeight = originalImage.Height;
        double aspectRatio = (double)originalImage.Width / (double)originalImage.Height;
        if (aspectRatio <= 1 && originalImage.Width > maxWidth)
        {
            newWidth = maxWidth;
            newHeight = (int)Math.Round(newWidth / aspectRatio);
        }
        else if (aspectRatio > 1 && originalImage.Height > maxHeight)
        {
            newHeight = maxHeight;
            newWidth = (int)Math.Round(newHeight * aspectRatio);
        }
        Bitmap newImage = new Bitmap(newWidth, newHeight);
        using (Graphics g = Graphics.FromImage(newImage))
        {
            //--Quality Settings Adjust to fit your application
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
            g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            g.DrawImage(originalImage, 0, 0, newImage.Width, newImage.Height);
            return newImage;
        }
    }
}

Tags: , , ,

Wednesday, January 26th, 2011 .NET, Programming No Comments

FMyScript Disappearing Voting Links

I was recently asked to work on a site running FMyScript. The problem was this every time a voting link was clicked the link would just disappear and the votes were not updated.

The solution was two fold:

Part 1:
The first problem was the voting links has a ‘ in the string such as “I’m really sad to hear that” So I just changed the string instead of finding all the places I might have to escape it. I figured I am is better grammar anyways.

Part 2:
The domain must the config file. That means if you set up your site with the www in the url and someone goes to your site without the www in the url the voting system will not work.

I modified the .htaccess files to force www by adding the following lines:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.your_domain.com$
RewriteRule ^(.*)$ http://www.your_domain.com/$1 [R=301]

I hope this helps someone.

Tags: , ,

Saturday, November 20th, 2010 Programming, Web Design 4 Comments

SoftArtisans OfficeWriter

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.

Tags: ,

Sunday, October 24th, 2010 Programming No Comments