Visual Studio 2010 Beta!!!

Well for MSDN Subscribers, Visual Studio 2010 Beta is live and available.

Jason Short posted a blog over here about it.

Some of the new features he stated:

  • .Net 4.0
  • Cloud Development - Windows Azure which is basically utility computing where you pay by the hour for your usage.
  • Parallel Development - Not sure if this only means PLINQ for .Net developers or if they are only talking about C++ devs.  
  • TDD Improvements - Editor changes for building test cases first, and then writing the code.
  • ASP.NET - CSS grids and design surfaces changes, more Javascript debugging improvements.
  • C++ Compiler - Lots of changes for C++ development, including MFC.
  • Sharepoint templates 
  • New Project Templates
  • Windows 7 - MFC updates for Ribbon UI, and WPF changes.
  • Application Model Changes - Reverse existing codebases, and lots of changes in Architect Edition to support more model types (including Class Libraries finally).
  • Test Runner - This is potentially huge as it allows testers to submit bug reports complete with callstacks and traces that you can actually use to resume an app at the error point to avoid the dreaded No Repro on bug reports.

Here the offical site, and the VS 2010 MSDN Channel with videos.


The last feature, Test Runner, sounds awesome!


US Passport Filed

Well I've sent away for my U.S. Passport so that I can take a trip somewhere. Not sure where I'd go yet, but open to suggestions! Wold rather go where there is someone I somewhat know or met online, rather then go somewhere where I know no one.



FTP with VB.Net

Someone recently mentioned they need to do some FTP stuff in their application, send up files and such to a remote server. Well, low and behold, I’ve already done that task before. So I thought I’d provide them some code to use.

It’s actually pretty easy, you just have to setup some Constents and then you could basically copy and paste my methods.

In this example I’m uploading a specific filename. Wouldn’t take much to modify to upload multiple’s.

Private _ServerFriendlyName As String = ConfigurationManager.AppSettings("FTPServerFriendlyName") '"Production Box Alpha"
Private _ServerAddressURI As String = "ftp://" & ConfigurationManager.AppSettings("FTPServerIP") '"
Private _ServerPath As String = "" '"/Logs"
Private _FTPUserName As String = ConfigurationManager.AppSettings("FTPUserName") '"ftpsusername"
Private _FTPPassword As String = ConfigurationManager.AppSettings("FTPPassword") ' "ftppass"
Private _FileToUploadFileName As String = "FileToUpload.txt"

Let’s go over the variables I have here.

_ServerFriendlyName – Just a var I use to show what server you are going too
_ServerAddressURI – this is the FTP address, feel free to use IP for FDQN
_ServerPath – this is where on the server I will dump my files into, in this case the user/pass already go into the /logs folder so this var is blank
_FTPUsername – obvious
_FTPPassword – obvious
_FTPToUploadFileName – this is the file I am planning to upload and download

On my page_load I am calling a DownloadFile function to get the file.

DownloadFile("/Logs/" & _FileToUploadFileName)

And here is the first copy function, the Download Method

Private Sub DownloadFile(ByVal FTPPath As String)
        Dim ListRequest As FtpWebRequest = WebRequest.Create(_ServerAddressURI & FTPPath)
        Dim Crendentials As New NetworkCredential(_FTPUserName, _FTPPassword)
        ListRequest.Credentials = Crendentials
        ListRequest.Method = WebRequestMethods.Ftp.DownloadFile
        Dim FTPResp As FtpWebResponse = ListRequest.GetResponse
        Dim FTPRespStream As Stream = FTPResp.GetResponseStream
        Dim Reader As New StreamReader(FTPRespStream, System.Text.Encoding.UTF8)
        Dim FileName = FTPPath.Substring(InStrRev(FTPPath, "/"))
        Dim FileLocation As String = HttpContext.Current.Request.MapPath("~/Logs/" & FileName)
        Dim DownloadedFile As New FileStream(FileLocation, FileMode.Create)
        Dim oWriteFile As New StreamWriter(DownloadedFile)
    Catch ex As Exception
        'Place your Error Handling Here
    End Try
End Sub

Afterwards, the user can modify the file as needed and then I upload it back when they are done. Notice I have on line 5, the MapPath(“~/Logs"/”….  that is the local path on the web server.  This should probably also be set at the top of my app and yours.  You send in the path you want to upload too

UploadFile("/Logs/" & _FTPToUploadFileName)
Private Sub UploadFile(ByVal FTPPath As String)
        Dim FileName As String = _ServerAddressURI & FTPPath
        Dim FileLocation As String = ""
        FileLocation = HttpContext.Current.Request.MapPath("~/Logs/" & _FTPToUploadFileName)
        Dim Client As New WebClient
        Client.Credentials = New NetworkCredential(_FTPUserName, _FTPPassword)
        Client.UploadFile(FileName, FileLocation)
    Catch ex As Exception
        'Put your Error Handling Here
    End Try
End Sub

Yes there are tweaks and that can be made, but you have enough to basically copy/paste and get a huge jump start.  You could also stream the file in from memory.

What was that? You want this code in c#? Well here you go, convert it :)

New .Net Language F#!!!

Come on, do we really need more languages out there? What the heck. F# is coming with next version of Visual Studio 2010.

Taken from a channel on MSDN,

“…F#, a new addition to the family of managed programming languages in Visual Studio 2010. F# is a multi-paradigm programming language. Though its focus is at functional programming, it's capable of producing object-oriented code like other .NET languages. Since it is a .NET language, it can interop just fine with other existing .NET languages.“

F# CTP from F# MSDN Dev Center:

“It combines the succinct, expressive, and compositional style of functional programming with the runtime, libraries, interoperability, and object model of .NET.”

Hmm, I’m going to have to see what this is about, and maybe give you an update. Intro Video here.

C# 3.0 gets Automatic Properties, Obj-C has it, and soon VB.Net

I know it’s been out for a little while now and most everyone that codes in C# knows but C# 3.0 has a new feature called Automatic Properties.  Objective-C for the iPhone has this ability as well, so I was kind of getting pampered in the XCode development environment using Obj-C.  I do a lot of VB.Net and sad to say that it doesn’t exist yet for VB.Net.  However it will with VB.Net v10 as mentioned a the Professional Developer Conference.

So in C# the old way…

private string _userName;
public string UserName
get { return _userName; }
set { _userName = value; }

becomes…. in C# v3.0

public string UserName {get; set;}

Your private properties are created for you by the compiler. Yes, yes you already know all this. Great. Why am I posting? Just that I felt VB.Net was getting no love and have been using a similar method in Objective-C.

In Objective-C you synthesize your properties, which basically means the same thing. In your header files you define the property with the property tag

@property int maximumNumberOfSides;

then in your implementation file you create a single line

@synthesize maximumNumberOfSides;
So in the upcoming VB.Net (Visual Basic.Net) v10..
9 lines of code…
Private _UserName As String
Private Property UserName() As String
Return _UserName
End Get
Set(ByVal value As String)
_UserName = value
End Set
End Property

becomes 1!
Public Property UserName As String

I’m so happy, I could cry.

YouTube and the WMG can suck it

So I’m a daily reader of Slashdot and TechDirt, and all the time I read how the RIAA is suing everyone and YouTube is taking down fair use videos and the world is falling apart with Copyright. To make matters worse Obama is hiring RIAA lawyers at the DOJ, ugh.

So none of this really effected me before. I read it and I agreed about the ridiculousness of it and complained in my head and moved on, hoping one day I’d see that article that says things are turning around. Until about 5 minutes ago. I made a FAIR USE video, a fake movie trailer, starring my friend, my car and my special effects. My friend is doing the voice over and I have a music track playing in the background, which I’ve looped in the beginning. I’ve had this video on YouTube for about 3 years now.

So I was showing someone my video, it’s over on the right there “Revenge Trailer” and first video below, and I’m thinking where did the audio go? Very weird, so I go to the YouTube site for the same video, and low and behold  see a NOTICE message under my clip, “This video contains an audio track that has not been authorized by WMG. The audio has been disabled.” WHAT!!??

The movie is crap now without the audio because the voice over is gone, the sound effects are gone. How embarrassing. Try watching your favorite show with no audio. It makes for a poor experience. I guess they thought this was better then taking it down.  Is there anyway to fight this or am I sol?

Here you can view the YouTube neutered version

Luckily I don’t think of YouTube as my storage server, so I have the original I made. I’m going to post it up on SoapsBox so hopefully they are smarter then YouTube. This recent one should have the audio.

My HomeMade Revenge Trailer

If all else fails you can download the original from this 11mb zip file.

Tell me, is this not fair use? And if so, what can I do about it?

Sorting a DataTable.Select into a Grid with or without using a DataView

I was debating with a friend on having to use a DataView to sort data from a DataTable. I had mentioned you could use the DataTable.Select function to sort your data without a DataView.  However, binding this data back to the GridView requires you to put the filtered rows back into a DataTable. So we went on to discuss which is better.

Normally, I would use the code below to loop through my filtered rows to manipulate them in some way, however this post is just to sort them without a DataView.

I’m using AdventureWorks database and pulling from Production.Product table.

So which is better? Without a DataView? DataTable to DataRow() to NewDataTable To GridView


With a DataView? DataTable to DataView to GridView

Private _ConnectionString As String = String.Empty
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub
    Private Sub PopulateGridViewWithoutDataView()
            Dim dtOriginalProductList As DataTable = GetListOfProducts.Tables(0) 'Get the datatable of products
            Dim drProducts() As DataRow = dtOriginalProductList.Select("1=1", "ListPrice DESC") 'select 1=1 brings back all rows, and then just sort
            Dim dtNewProductList As DataTable = dtOriginalProductList.Clone 'create datatable to hold new list (to bind to gridview)
            For Each drProduct As DataRow In drProducts 'Put new list of data into the new datatable 
            gvProductsWithoutDataView.DataSource = dtNewProductList 'Set
            gvProductsWithoutDataView.DataBind() 'Bind
        Catch ex As Exception
            'Error handling code here
        End Try
    End Sub
    Private Sub PopulateGridViewWithDataView()
        Dim dtOriginalProductList As DataTable = GetListOfProducts.Tables(0) 'Get the datatable of products
        Dim dvProductList As New DataView 'Create DataView
        dvProductList.Table = dtOriginalProductList 'Load DataTable
        dvProductList.Sort = "ListPrice DESC" 'Sort Property
        gvProductsWithDataView.DataSource = dvProductList 'Set
        gvProductsWithDataView.DataBind() 'Bind
    End Sub
    Public Function GetListOfProducts() As DataSet
        Dim oDS As New DataSet
            _ConnectionString = ConfigurationManager.ConnectionStrings("DefaultConnectionString").ConnectionString
            oDS = DataAccess.SqlHelper.ExecuteDataset(_ConnectionString, CommandType.Text, "SELECT ProductID, Name, ProductNumber, StandardCost, ListPrice FROM Production.Product")
            Return oDS
        Catch ex As Exception
            Throw ex
        End Try
    End Function

PopulateGridViewWithoutDataView – This method binds products to the gridview that have been sorted by using DataTable.Select  Benefits I see is that even though you have to import the new rows into a another datatable before binding, you can then manipulate this new datatable anyway you see fit. Ex. Pulling a certain row back after it’s been sorted.

PopulateGridViewWithDataView – This method binds products to the gridview that are sorted via a DataView and then bound to the GridView. This method is great as well, except if you want to manipulate the data or pull rows from the datatable by index based on the sorted view. This will reference the real row in the original datatable and not from the dataview itself. So if you need to manipulate the data, then go without using a dataview. However, if you don’t have to touch the data or pull certain rows, then use the DataView method.

SilverLight App Demonstrating Error Handling

Now first thing you should know is this SilverLight app is meant to error and crash.

I was messing around with some Error Handling and just thought I’d post up my demo app. I designed it using Expression Blend 2 SP1 and for SilverLight 2.0

Here’s the logic I wanted to portray…

User attempts to login and on doing so the SilverLight application crashes and they are forced to reload. Forcing the page to reload would typically lose your information. Also, user fails to try and login and we capture those errors and display them on the screen.

Now the output doesn’t look like much, the real value is in the code behind it.

On App Load:

1) App loads and looks for my webservice to provide the BirthYears which binds to the ComboBox. If it cannot find my WebSerivce or the service is down the app captures the error and display a friendly version on the control.

2) I check to see if you have data in the SilverLight Isolated Datastore and if you do I will populate the username into the textbox, simulating the effort of putting things back to the way they were before. (though it might seem like nothing to you, since most login boxes remember your username, this one does not. It’s a coded/manual process)

From my DataStore class which I call, these methods I placed into it

Public Function LoadUser() As User
    Dim User As User = Nothing
        'Instantiate App Store
        Using store As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
            'If the Store is there
            If store.FileExists(DATA_STORE_NAME) Then
                'Lets read it and create a user from the info
                Dim sr As IsolatedStorageFileStream = store.OpenFile(DATA_STORE_NAME, IO.FileMode.Open)
                Using reader As New IO.StreamReader(sr)
                    Dim strDataLine As String = reader.ReadLine
                    If strDataLine IsNot Nothing Then
                        Dim userValues As String() = Split(strDataLine, ";")
                        'UserName.ToString & ";" & Password.ToString & ";" & BirthYear.ToString & ";" & strLastVisit & ";" & IsAuthenticated.ToString
                        Dim BirthYeaer As Integer
                        Integer.TryParse(userValues(2), BirthYeaer)
                        Dim IsAuthenticated As Boolean
                        Boolean.TryParse(userValues(4), IsAuthenticated)
                        User = New User(userValues(0), userValues(1), BirthYeaer, userValues(3), IsAuthenticated)
                        User = New User()
                    End If
                End Using
                User = New User()
            End If
        End Using
    Catch ex As Exception
        Throw ex
    End Try
    Return User
End Function

Scenario 1: Attempt to login with no username or password. App page checks for it and display you a nice message. I’ve sent the error to window as an alert as well as the TextBlock control, just to demonstrate. Easy as pie.

If tbUsername.Text = String.Empty OrElse tbPassword.Password = String.Empty Then
     lblMessage.Text = "You must provide both a Username and a Password"
     HtmlPage.Window.Alert("You must provide both a Username and a Password")
End If

Scenario 2: Attempt to login with any information, doesn’t matter, as long as it’s not blank. This is there the big change comes in. When you try and login as anything but the only user hard-coded into the system. The app throws an error, some critcal error.  You get the alert to then reload the application. At this point in my try…catch I write out data to the SilverLight’s isolated datastore.

Public Sub SaveUser(ByVal User As User)
        'Instantiate App Store
        Using store As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
            Dim sw As IsolatedStorageFileStream = store.OpenFile(DATA_STORE_NAME, IO.FileMode.OpenOrCreate)
            Using writer As New IO.StreamWriter(sw)
            End Using
        End Using
    Catch ex As Exception
    End Try
End Sub


Unhandled Exceptions: These are a little different. However, in SilverLight you can use the event “Application_UnhandledException” in the App.xaml file and try and come back from an exception. Such as checking to see if you get a communication error and notifying the user, with the ability to cancel the exception and return back to the application.  Most times, we’ll do some cleanup if we can and log the error via a web service to a server to be handled.  The goal here would be to save some information about the application, maybe to have JavaScript fire on the onError event, and try and capture what data it can from the application. Then on reload try and put things back to the way they were before the crash. If the Handled property of ApplicationUnhandledExceptionEventArgs in App.xaml is set to false then JavaScript can capture the error (assuming you set the onError property on the control) and then you get your nice white screen of death. You can excute some js to reload the control.  I didn't demo this here as this plugin is running on my blog and I'd have to toss up some js to capture for it.

A decent book I’d recommend is this one:




Silverlight 2 Unleashed by Laurent Bugnion

Silverlight 2 Recipes: A Problem-Solution Approach by Jit Ghosh, Rob Cameron

Embedding SilverLight into my BlogEngine.Net site

Like others, people want to add SilverLight apps or plugins to their blog site and now so do I! However, on quick searching I found an Extension that I didn’t like. It’s using 1.0 older js file and seems ok but I wanted something more up-to-date. Others have pointed out flawless.code’s silverlight plugin but I kept looking.

I found a better one in my opinion, because it relies on me having the latest SilverLight.js file and I can put the content in another folder, which I am doing. So I tried out MonstersGotMy.Net’s SilverLight Extension for BlogEngine.Net and it was much more to my liking.

image (1.51 kb)

Where did your photos go!?

Ok I’ve been asked this a few times now. Sorry my original gallery is gone. I plan to put something up, I’m just not sure what technology I’m going to use. I could manually upload images but that’s no fun. I think I’m leaning towards using my Mac’s iPhoto or account, or iWeb to handle my gallery.  Soon as I get that sorted out, I’ll create a menu link to it.