Getting command line parameters or seeing if they are present is not as easy as you would think. I whipped up some code to make this flexible and easy.

   Private Const ParameterPrefix As Char = "/"c
       
   Private Function GetCommandLineArgument(ByVal parameter As String) As String
      Dim paramValue = String.Empty
      For Each tempValue As String In System.Environment.GetCommandLineArgs
         If tempValue.Contains(ParameterPrefix + parameter + "=") Then
            paramValue = tempValue.Split(Char.Parse("="))(1).ToString().Trim()
            Exit For
         End If
      Next
      Return paramValue
   End Function
   Private Function CommandLineArgumentExists(ByVal parameter As String) As Boolean
      Dim exists = False
      For Each tempValue As String In System.Environment.GetCommandLineArgs
         If tempValue.Contains(ParameterPrefix + parameter) Then
            exists = True
            Exit For
         End If
      Next
      Return exists
   End Function
   Private Function GetCommandLineArgument(ByVal parameter As String, ByVal prefix As String) As String
      Dim paramValue = String.Empty
      For Each tempValue As String In System.Environment.GetCommandLineArgs
         If tempValue.Contains(prefix + parameter + "=") Then
            paramValue = tempValue.Split(Char.Parse("="))(1).ToString().Trim()
            Exit For
         End If
      Next
      Return paramValue
   End Function
   Private Function CommandLineArgumentExists(ByVal parameter As String, ByVal prefix As String) As Boolean
      Dim exists = False
      For Each tempValue As String In System.Environment.GetCommandLineArgs
         If tempValue.Contains(prefix + parameter) Then
            exists = True
            Exit For
         End If
      Next
      Return exists
   End Function

Usage:

 Debug.WriteLine(CommandLineArgumentExists("source"))
 Debug.WriteLine(GetCommandLineArgument("source", "-"))

Tip Submitted By: David McCarter


 
Categories: Development | VB.NET

Here is some easy, generic code to serialize your objects to and from JSON:

Public Shared Function JsonEncode(ByVal input As Object) As String
  Dim serilizer = New DataContractJsonSerializer(input.GetType)
  Using ms = New MemoryStream()
    serilizer.WriteObject(ms, input)
    Return Encoding.Default.GetString(ms.ToArray())
  End Using
End Function
Public Shared Function JsonDecode(Of T)(ByVal input As String) As T
  Using ms = New MemoryStream(Encoding.Unicode.GetBytes(input))
    Dim serilizer = New DataContractJsonSerializer(GetType(T))
    Return DirectCast(serilizer.ReadObject(ms), T)
  End Using
End Function
public static string JsonEncode(object input)
{
var serilizer = new DataContractJsonSerializer(input.GetType());
  using (var ms = new MemoryStream())
{
serilizer.WriteObject(ms, input);
    return Encoding.Default.GetString(ms.ToArray());
}
}
public static T JsonDecode<T>(string input)
{
using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(input)))
{
var serilizer = new DataContractJsonSerializer(typeof(T));
    return (T)serilizer.ReadObject(ms);
}
}

Tip Submitted By: David McCarter


 
Categories: ASP.NET | C# | JavaScript | VB.NET | Web Services | Generics

June 30, 2008
@ 02:33 PM

I recently started a new job that uses C#. I have been trying for two frickin hours to get Trace Listeners working in an application here with no luck at all. So to test that I have the web.config setup correctly, I added the following:

var log = new Microsoft.VisualBasic.Logging.Log();
log.WriteEntry("VB Log");

Bam, it works! Dang I LOVE VB.NET! Now I'm going to go ask my boss if I can use the VisualBasic.Logging class in our C# application ;-)

David McCarter


 
Categories: ASP.NET | VB.NET

If you live in the San Diego area, dotNetDave (a.k.a. David McCarter) will be teaching a 6 week Building Rich & Interactive Web Applications with ASP.NET AJAX course at the University of California, San Diego Extension beginning on Thursday 7/17/2008 from 5:30pm to 10:00pm. For more information and to enroll, please click here.


 
Categories: AJAX | ASP.NET | dotNetDave

June 1, 2008
@ 08:55 AM
Code

I hope everyone in southern California is planning to attend this years SoCal Code Camp up at University California San Diego on 6/28 - 6/29. It's always a great time and lots of free training! I will also be selling a limited number of my latest book "David McCarter's .NET Coding Standards" at my sessions for $11, cheaper than the web site (no tax and shipping), please bring exact change.

I will be presenting the following sessions and I hope you will attend.

dotNetDave's .NET Utility Assembly (My First CodePlex Project)

10:15 AM - Sunday, June 29, 2008 - Location: 141

zip_icon.gif dotNetDaves .NET Utility Assembly1.zip (1.11 MB)

CodePlex site: http://www.codeplex.com/dotNetTipsUtility

Building Rich & Interactive Web Applications with ASP.NET AJAX Part 1

8:45 AM - Saturday, June 28, 2008 - Location: 129

zip_icon.gif Building Rich & Interactive Web Applications with ASP.NET AJAX.zip (1.83 MB)

Building Rich & Interactive Web Applications with ASP.NET AJAX Part 2 

12:15 PM - Saturday, June 28, 2008 - Location: 129

zip_icon.gif Building Rich & Interactive Web Applications with ASP.NET AJAX Part 2 - 20081.zip (1.82 MB)

Why You Need .NET Coding Standards (2008)

1:45 PM - Sunday, June 29, 2008 - Location: 127

zip_icon.gif Why You Need .NET Coding Standards-20081.zip (2.86 MB)

Pictures and Video

Fullerton Code Camp - JAN 2008

Pictures from This Years Code Camp:

Pictures from past SoCal Code Camps:

Video from past Code Camps:

 


 
Categories: .NET | AJAX | ASP.NET | Code Camp | Csharp | Defensive Programming | Development | dotNetDave | News | VB.NET

As you might find out the hard way, the .NET redistributable does not include the files required for the Reporting Services ReportViewer control. This is an issue for web servers when deploying ASP.NET applications that use this control. You can download the redistributable files below:


 
Categories: ASP.NET | Link

Ever wonder what all the shortcut keys are in Visual Studio? Well now you can print a poster of them:


 
Categories: Link | VS.NET

I built a page that uses the ASP.NET AJAX UpdatePanel and within it I placed a GridView control that connects to a DataSet (that uses TableAdapers to a SQL Server 2005 database back end) using a DataSource control. I do not use paging in the GridView so that the user can print all of the items in the grid. I noticed that when there are a lot of items in the grid, about 25 or more, the load of the UpdatePanel became very slow. I figured it was my virtual machine, but this even happened on our production server and users even commented on it.

I did the normal things like checked the queries and even looked at the page tracing to determine what controls might be causing the issue. I could not find where the slowdown was coming from. Then, just to try it, I moved the DataSource control for the GridView out of the UpdatePanel. Low and behold the update sped up around 300% - 400%!

My only guess is when the DataSource control was being recreated every time the UpdatePanel was loaded and this just takes time. So now as part of my common practice, I put all DataSource controls at the bottom of the page. It would be nice if the designer did this automatically.

Tip Submitted By: David McCarter


 
Categories: AJAX | ASP.NET

May 12, 2008
@ 12:59 PM

This project gives you access to the code for upcoming releases that the Microsoft ASP.NET team is working on. The project gives you a look at the design and lets you have a voice in it.

http://codeplex.com/aspnet


 
Categories: ASP.NET | Link

April 14, 2008
@ 09:34 AM
If you live in the San Diego area, dotNetDave (a.k.a. David McCarter) will be teaching a 6 week Fundamentals of the .NET Framework course at the University of California, San Diego Extension beginning on Thursday 5/14/2008 from 5:30pm to 10:00pm. For more information and to enroll, please click here.


 
Categories: .NET | Csharp | dotNetDave | VB.NET

One of the features I use often with the Microsoft Web Service Enhancements (WSE) is logging. It's a great feature where it logs everything coming in and out of a web service. When someone calls me with issues, the first thing I do is turn this on in the web.config and watch the data coming and going. The data is stored in two different xml files. One for incoming calls and one for responses.

The problem I just ran into is that I got a call that stated web service calls that were taking about 1 second or less were now taking 20 seconds or even timing out. After working on the issue off and on for two days I discovered that these two WSE log files have grown to 59MB+ because I forgot to turn off logging the last time there was an issue! Once I turned off logging this issue went away.

One symptom that we noticed that made us go down the wrong direction at first was that the w3wp.exe in Task Manager would eat a lot of memory during those 20 seconds and spike the CPU usage up to 99%! When we Googled this, we found lots similar issues, but none relating to the xml log files generated by WSE. We wasted a lot of time on this.

I hope this helps anyone else that uses logging in WSE.

Tip By: David McCarter


 
Categories: Web Services

If you are a student at a university, you can get a free copy of Visual Studio 2008 Professional and other Microsoft software. Got to this link: https://downloads.channel8.msdn.com/Products/Visual_Studio_2008.aspx


 
Categories: Link | News | VS.NET

March 10, 2008
@ 08:38 AM

The ASP.NET 3.5 Extensions Preview is a preview of new features being added to ASP.NET 3.5 and ADO.NET.

http://www.microsoft.com/downloads/details.aspx?FamilyID=A9C6BC06-B894-4B11-8300-35BD2F8FC908&displaylang=en


 
Categories: ADO.NET | AJAX | ASP.NET | Link

SQL Server Compact 3.5 is a small footprint in-process database engine that allows developers to build robust applications for Windows Desktops and Mobile Devices. This download contains the Books Online and Samples for SQL Server Compact 3.5
 

 
Categories: ADO.NET | Compact Framework | Link

I found out the hard way in the last two days that an SQL Server CE database does not work properly when creating a typed Dataset with a ASP.NET 3.5 application. Sure, you can create one in the IDE, but the code-on-the-fly will not be generated therefor you can't use it in your code. Actually causes an error if you try to build.

Rec'd an confirmation from Microsoft today that they did not implement this for ASP.NET. Just wanted to warn you so you don't waste an hour plus like I did. If you still want to use SQL Server CE and typed DataSets in ASP.NET you will need to create a separate assembly (which should be done anyway). Oh, won't work with LINQ either.


 
Categories: ADO.NET | ASP.NET | Compact Framework | SQL Server | LINQ

I needed to update a program and when I brought it up in VS 2008, it changed the version of Crystal Reports to 10.5.3700. This presented a challenge to get the required Crystal files onto the production server. Of course using the VS web publish feature does not do this even though I wish it did. So I went to the Business Objects site (makers of Crystal Reports) to search for an install. I first download the version for 2008... made sense to me, but it actually turned out to be version 12.

Then I tried the download for CrystalReports 2008 ClickOnce Package for Visual Studio 2005 since it said it was version 10. Unfortuneatly it did not say what minor version it was. This turned into a headache because it kept asking me for a product ID before the install would continue. I followed the instructions and got the number from VS 2008 and that did not work. Even spend time registering Crystal with Business Objects and that did not work either. I tried to create a support case on their web site and that was not even working!

After many hours of frustration, I did a search of my hard drive of ANY file that started with "Crystal" and I finally found it! The installs are located in this directory:

C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\CrystalReports10_5

The files are either CRRedist2008_x86.msi or CRRedist2008_x64.msi. I installed them on the server and everything worked fine.

I hope this might save you from all the the wasted time I went through. Another reason why I love Microsoft Reporting Services!!!

Tip Submitted By: David McCarter


 
Categories: ASP.NET | Reporting