While I really love the online VB.NET to C# and C# to VB.NET code converters provided by developerFusion, I have also found the open source SharpDevelop application to be a very good tool for converting .NET code from one flavor to another. It is especially good at converting whole projects or larger amounts of code. I think it is worthy a post:
http://www.icsharpcode.net/OpenSource/SD/
Code Conversion Features:
http://community.sharpdevelop.net/blogs/mattward/articles/FeatureTourCodeConversion.aspx
Code Conversion is one very small part of SharpDevelop. The rest is worth a look too!
This blog is a depository for things I have found regarding VB.NET and C#.NET development (and other things I may need to remember). This blog is primarily for my own reference, but if the information I found is useful to others, then that is great. If others want to contribute with comments or other information, then that is great too.
Thursday, June 25, 2009
Friday, June 5, 2009
Converting a Byte Array to a String in VB.NET
Here is one way to convert a byte array to a String in VB.NET:
Dim bArray() As Byte = {65, 66, 67, 68, 69}
Dim str As String
str = System.Text.Encoding.ASCII.GetString(bArray)
More examples of converting Byte Arrays to Strings and vice versa in VB.NET and C# can be found here:
http://www.chilkatsoft.com/faq/DotNetStrToBytes.html
Dim bArray() As Byte = {65, 66, 67, 68, 69}
Dim str As String
str = System.Text.Encoding.ASCII.GetString(bArray)
More examples of converting Byte Arrays to Strings and vice versa in VB.NET and C# can be found here:
http://www.chilkatsoft.com/faq/DotNetStrToBytes.html
Labels:
Byte Array,
String
Getting Application Path for a Console App
In a previous post, I gave examples of getting the Application Path for a Windows Form app and a Windows Mobile app. Getting the Application Path for a Console app is similar to getting one for the Windows Mobile app:
Dim appPath As String = _
System.IO.Path.GetDirectoryName( _
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
Dim appPath As String = _
System.IO.Path.GetDirectoryName( _
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
Labels:
AppStartupPath
Monday, May 18, 2009
TechEd 2009 in Los Angeles

This year the TechEd Developers Conference was merged with the TechEd IT conference and happened last week in Los Angeles. While there were significantly fewer Developer oriented sessions, it was interesting to sit in some of the IT sessions. With around 700 sessions to choose from and only about 20 you can actually attend, the need to be particular about what you want to learn becomes very important. I heavily weighted my track with “Mobile”, but I also checked out SQL Server’s Spatial capabilities, and the future directions of the development environments and programming languages.
The push, I mean focus, this year was definitely the yet to be released Windows 7 and Windows Server 2008 R2, followed by a healthy dose of Virtualization in the form of Hyper-V and Windows Virtual PC.
I did have an opportunity to run my apps on a beta copy of Windows 7 at the “Bring Your Own App Lab.” There were a few glitchy things with reading some values out of the registry, but overall I was very pleased with how my apps worked the first time on Windows 7. I have already checked off a lot of grief on my to-do list from this experience. The free booze they were passing out was not even necessary to favorably color my opinion of Windows 7.
The focus last year was definitely LINQ, which seems to have been toned down now to is actual value. WPF and Silverlight, looked cool to try, but now they look usable. Microsoft’s creation of tools to help spawn the development of new programming languages is supposed to bring about an explosion in new languages. I along with everyone else in the Polyglot Programmer session cringed at the idea of having to learn dozens of new languages, but like LINQ, this idea may fade into a manageable and productive tool in our programming arsenal. I was hoping to see Windows Workflow (WF) be a hotter topic than it apparently is, but it may take a few iterations before it catches on.
I was pretty pleased with TechEd 2009. I will continue to process the information for a while.

Labels:
TechEd 2009
Tuesday, May 5, 2009
Scaling one Rectangle to fit in Another Rectangle
Here is a great posting that shows several approaches to scaling one rectangle to fit inside of another:
http://www.vbdotnetforums.com/graphics-gdi/33829-scale-rectangle-fit-another.html
http://www.vbdotnetforums.com/graphics-gdi/33829-scale-rectangle-fit-another.html
Monday, April 13, 2009
GetComputerName equivalent in VB.NET and C#
The Win32Api GetComputerName has a simpler equivalent in the .NET world:
Dim compName as String = Environment.MachineName.ToString
Dim compName as String = Environment.MachineName.ToString
Labels:
GetComputerName,
MachineName
Wednesday, April 8, 2009
Getting the Version of an OleDB Provider
There may a much simpler way of determining the version of an OleDb provider (like OraOledb.Oracle.1) than I have shown below, but I have yet to find one.
The OleDbConnection object will tell you the version of the Server through its ServerVersion property:
Dim myConn As New OleDbConnection(g_gtech.GetConnectionString)
myConn.Open()
Dim versionStr as String = myConn.ServerVersion.ToString
myConn.Dispose()
But, I often want to the know the version of the Provider itself. The only way I have found to do this is to sift through the registry and read the ProductVersion off the provider DLL itself.
For example:
Dim versionStr as String = _
GetProviderVersion("OraOleDb.Oracle.1")
Here is the supporting code:
Public Function GetProviderVersion(ByVal providerName As String) As String
Try
Dim clsid As String = GetRegistryValue(Registry.LocalMachine, _
"SOFTWARE\Classes\" + providerName + "\clsid", "")
If clsid.Trim = "" Then Return "Not Installed"
Dim path As String = _
GetRegistryValue(Registry.LocalMachine, "SOFTWARE\Classes\CLSID\" + clsid + "\InprocServer32", "")
Dim Info As FileVersionInfo
Info = FileVersionInfo.GetVersionInfo(path)
Return Info.ProductVersion.ToString
Catch ex As Exception
Return "Unable to get Version"
End Try
End Function
Public Function GetRegistryValue(ByVal regKey As RegistryKey, _
ByVal subKey As String, ByVal valueName As String) As String
Dim value As String = ""
Dim registryKey As RegistryKey = regKey
Dim registrySubKey As RegistryKey
registrySubKey = registryKey.OpenSubKey(subKey)
If registrySubKey IsNot Nothing Then
Try
value = registrySubKey.GetValue(valueName).ToString
Catch ex As Exception
value = ""
End Try
registrySubKey.Close()
End If
Return value
End Function
If there is a simple or more elegant way to find the Provider version, please comment.
The OleDbConnection object will tell you the version of the Server through its ServerVersion property:
Dim myConn As New OleDbConnection(g_gtech.GetConnectionString)
myConn.Open()
Dim versionStr as String = myConn.ServerVersion.ToString
myConn.Dispose()
But, I often want to the know the version of the Provider itself. The only way I have found to do this is to sift through the registry and read the ProductVersion off the provider DLL itself.
For example:
Dim versionStr as String = _
GetProviderVersion("OraOleDb.Oracle.1")
Here is the supporting code:
Public Function GetProviderVersion(ByVal providerName As String) As String
Try
Dim clsid As String = GetRegistryValue(Registry.LocalMachine, _
"SOFTWARE\Classes\" + providerName + "\clsid", "")
If clsid.Trim = "" Then Return "Not Installed"
Dim path As String = _
GetRegistryValue(Registry.LocalMachine, "SOFTWARE\Classes\CLSID\" + clsid + "\InprocServer32", "")
Dim Info As FileVersionInfo
Info = FileVersionInfo.GetVersionInfo(path)
Return Info.ProductVersion.ToString
Catch ex As Exception
Return "Unable to get Version"
End Try
End Function
Public Function GetRegistryValue(ByVal regKey As RegistryKey, _
ByVal subKey As String, ByVal valueName As String) As String
Dim value As String = ""
Dim registryKey As RegistryKey = regKey
Dim registrySubKey As RegistryKey
registrySubKey = registryKey.OpenSubKey(subKey)
If registrySubKey IsNot Nothing Then
Try
value = registrySubKey.GetValue(valueName).ToString
Catch ex As Exception
value = ""
End Try
registrySubKey.Close()
End If
Return value
End Function
If there is a simple or more elegant way to find the Provider version, please comment.
Subscribe to:
Posts (Atom)