Convert Pipe Delimited File to CSV File and Choose and Reorder Columns

A friend need a small program to take a Pipe file and convert it to a CSV file. Easy enough, replace the “|”,s with “,”’s.  Until you add more requirements, allow the user to choose which columns they want to convert over and allow them to re-order the columns and save the file as something else.  Ok now you’re talking about streamreaders, streamwriter, some type or reorder control and choosing columns. Turning a 45min project into a  3 hour project going at full pace, as I’m not much of a Windows Form developer, I generally stick in the asp.net world.

Anyway.. here’s the project in VB.Net and source code.

The executable is in it’s default location TextPipeConverter\TextPipeConverter\bin\Debug\TextPipeConverter.exe

Notes: There’s no error checking, very minor, no try catches, quick and dirty.

Casting Types in VB.Net and More

Source: Cheat Sheet - Casting in VB.NET and C#

Great little find, and since I’m a VB.Net whore, I’ll just post up the VB.Net version :)

Casting in VB.NET

  1. By default in VB, casting is automatically done for you when you assign objects to variables. The objects are then automatically casted to the variables' type.

    This behavior can be influenced by an option line on top of your code file:

    Option Strict On
    Option Strict Off

    When on, casting is strict and not automatic.

  2. Explicit casting can be done with the cast operator CType() or DirectCast():

    textbox = CType(obj, TextBox)
    textbox = DirectCast(obj, TextBox)


    The difference between the two keywords is that CType succeeds as long as there is a valid conversion defined between the expression and the type, whereas DirectCast requires the run-time type of an object variable to be the same as the specified type. If the specified type and the run-time type of the expression are the same, however, the run-time performance of DirectCast is better than that of CType. DirectCast throws an InvalidCastException error if the argument types do not match.

  3. Testing if an object is of a particular type, can be done with the TypeOf...Is operator:

    If TypeOf obj Is TextBox Then...
  4. Obtaining a System.Type object for a given type can be done with the GetType operator:

    Dim t As System.Type
    t = GetType(String)
    MessageBox.Show(t.FullName)
  5. Obtaining a System.Type object for a given object can be done with the GetType method:

    Dim t as System.Type
    t = obj.GetType()
    MessageBox.Show(t.FullName)

Now to build on and add one more of my own…

Get the type based on an arbitrary string.

System.Type.GetType("System.String")

Problem with this though is you can not use it to cast using CType or DirectCast. Looking at the CType Function..

typename - Any expression that is legal within an As clause in a Dim statement, that is, the name of any data type, object, structure, class, or interface.

You can only use types that are compiled and can’t use types that show up at runtime. So trying to use CType(obj, System.Type.GetType(“System.String”)) will only get you an error.  Array bounds cannot appear in type specifiers.

How to get around this? I have no freaking idea, yet. I’m think I might could create a custom type of my own and do something so that it converts to the proper method but for now I’ll just catch a few ArgumentExceptions and try different cast types then.

HTTP Error 404.17 Not Found – Using WCF .SVC Service

So you’re getting IIS error’s when trying to run a .svc file that’s coded to use WCF or Windows Communication Foundation.

HTTP Error 404.17 - Not Found

The requested content appears to be script and will not be served by the static file handler.

or maybe..

HTTP Error 404.3 - Not Found

The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.

Took me awhile to realize I need to setup/configure IIS and WCF properly.  Here are the steps from MS, I went through and realized I had missed one component (IIS6 Scripting tools, who would have thought), which I probably didn’t need, but the big ones that I didn’t have WCF Http Activation installed.  After that, I registered WCF..

"%WINDIR%\Microsoft.Net\Framework\v3.5\WFServicesReg.exe" /c

and then I was golden, but there might be other things you are lacking or missing. So go through all the steps.

One-Time Set Up Procedure for the Windows Communication Foundation Samples

Set the DefaultButton inside a LoginView Control in a MasterPage

Ok if you google this you’ll get some solutions that say set the DefaultButton to ParentControlID$ButtonID

However, this didn’t work for me. I kept getting the same error no matter what I tried.

The DefaultButton of '<PanelID>' must be the ID of a control of type IButtonControl.

So I tried another approach that worked great.

On page load I found the Panel Control and found the button control and set the default button programmatically.

<asp:LoginView ID="LoginView1" runat="server">
    <AnonymousTemplate>
        <asp:Panel ID="pnlLogin" runat="server">
            <telerik:RadTextBox ID="tbUsername" runat="server" EmptyMessage="Username" />&nbsp;
            <telerik:RadTextBox ID="tbPassword" runat="server" EmptyMessage="Password" TextMode="Password" />&nbsp;
            <div id="SignIn" style="position: relative; z-index: 1; float: right; bottom: 21px;">
                 <asp:LinkButton ID="lbSignIn" runat="server" Font-Bold="true" Font-Size="Small" Text="SIGN IN" OnClick="lbSignIn_Click" />
            </div>
            <div id="divLoginLinks" style="position:relative; clear:both">
                <span class="GrayFooterFont"><asp:HyperLink ID="hlRegister" runat="server" Text="Register" NavigateUrl="~/Registration.aspx" /> | <asp:HyperLink ID="hlForgot" runat="server" Text="Forgot Password" NavigateUrl="~/ForgotPassword.aspx" /></span>
            </div>
        </asp:Panel>
    </AnonymousTemplate>
    <LoggedInTemplate>
        <small><asp:Label ID="lblLoggedInUsername" runat="server" /> | <asp:LinkButton ID="lbSignOut" runat="server" Text="SIGN OUT" OnClick="lbSignOut_Click" /></small>
        <asp:LinkButton ID="lbSignIn" runat="server" Font-Bold="true" Font-Size="Small" Text="SIGN IN" OnClick="lbSignIn_Click" CssClass="hidden" />
    </LoggedInTemplate>
</asp:LoginView>

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    'If User is not logged in do this        
    Dim pnlLogin As Panel
    Dim lbSignIn As LinkButton
    pnlLogin = CType(LoginView1.Controls(0).FindControl("pnlLogin"), Panel)
    lbSignIn = CType(LoginView1.Controls(0).FindControl("lbSignIn"), LinkButton)
    pnlLogin.DefaultButton = lbSignIn.ID
    pnlLogin = Nothing
    lbSignIn = Nothing
End Sub

I’m sure I could have just hardcoded the lblSignIn ID to the pnlLogin, but no idea why I didn’t.

Play Ripped DVD’s on Windows Media Center

For Windows Vista:

Open Registry Editor (Start, Run, REGEDIT) and navigate to:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Media Center\Settings\DvdSettings

Double-click the key ShowGallery and change the value from “Play” to “Gallery”.

For Windows 7:

Don’t need it, it’s already built this way.

jQuery Plug-In Links I’ve collected

Here some links I’ve received from friends and have run across that have some cool jQuery plug-ins that I would like to use one day.

 

SilverLight Reference Controls

Reference a control that’s is outside your View, or on your MainPage if you’re using NavigationFrame or your “Parent” window.

Assumption: MainPage UserControl page is your starting page and has a NavigationFrame and a View is loaded in a content window.

Method 1: (Assuming “MainPage” is the name of your MainPage or the x:Class it uses, x:Class="<AppName>.MainPage" and the TextBlock named “lblStep1”)

Dim Main As MainPage = CType(<AppName>.App.Current.RootVisual, MainPage)
        CType(Main.FindName("lblStep1"), TextBlock).Text = "Hello Test123"

Or Method 2:

CType(CType(<AppName>.App.Current.RootVisual, MainPage).FindName("lblStep1"), TextBlock).Text = "Updated Text"
 

 

Reference a Control in a User Control that’s on the same view.

  1. CType(siTest.FindName("lblStep1"), TextBlock).Text = "Testing"

Test SMTP Server via Telnet

As a developer I always have to write code to send emails, here's a quick way as a developer to make sure the SMTP Server is working properly.

Telnet to Port 25 to Test SMTP Communication

1. Telnet into Exchange or SMTP Server using port 25.
Command is telnet <servername> 25

c:\>telnet 192.168.0.5 25
220 fredmastro.com Microsoft ESMTP MAIL Service, Version: 6.0.3790.1830 ready at Sun, 29 Nov 2009 10:22:22 -0400

2.Start by typing the following:
helo <your domain name><enter>                 
response should be as follows
250 OK

 

c:\>helo
250 fredmastro.com Hello [10.x.x.x]



3. Type the following command to tell the receiving SMTP server who the message is from:

mail from: <your Email Address><enter>
response should be as follows
250 OK - mail from <your Email address>

For example,

c:\>mail from: fredmastro@fredmastro.com
250 2.1.0 fredmastro@fredmastro.com....Sender OK



4.Type the following command to tell the receiving SMTP server whom the message is to. Use a valid recipient SMTP address in the domain that you are sending to.

For example, if you are sending to someguy@gmail.com, you must be certain that someguy@gmail.com exists in your domain. Otherwise, you will receive an NDR.

rcpt to: <recipient address><enter>
response should be as follows
250 OK - Recipient <recipient address>

For example, 
c:\>rcpt to: someguy@gmail.com
250 2.1.5 someguy@gmail.com

5.Type the following command to tell the SMTP server that you are ready to send data:

data<enter>
response should be as follows
354 Send data.  End with CRLF.CRLF

c:\>data
354 Start mail input; end with <CRLF>.<CRLF>
Test Message
.

250 2.6.0 <someguy@gmail.com>
Queued mail for delivery

6. Close the connection by typing the following command:
c:\>QUIT

response should be as follows:
221 closing connection

Another good reference: http://www.messagingtalk.org/content/470.html