OCDProgrammer.com

It's Microsoft's World, and I'm just living in it
View Clarence Klopfstein's profile on LinkedIn

Clarence Klopfstein's Facebook profile

This site is under construction...

Categories

New Comments

Referring Sites


Disclaimer

  • This is MY blog. The views represented here are not in relation to anybody else. Please read my full disclaimer for a more complete disclaimer.

Making Movies In Vista

December 13, 2008 07:02 by ckincincy

image One of the big weaknesses of having a Window's operating system was dealing with large files, specifically movies.  In XP I never could get consistency  and stability. From the editing to the writing of the DVD. 

Having recently upgraded to Vista Ultimate, I had my first job where I needed to take some footage that I had captured and make it into a movie.  Vista gets an A+. 

I used all 'out of the box' software and was able to create a decent movie from the files I had.  Then I burned it to five DVD's without a single failure.  That is the biggest thing to me. Many times previously that was so unreliable that I'd resort to going to my old employer's and use their MAC!

First I took my AVI that I had captured previously, opened up Windows Movie Maker and made some edits to the file.  With some title screen's, transitions and effects.  Added a photo gallery at the end of the movie, then went to 'Publish' my movie.  I needed to create some DVD's so next Windows  DVD Maker popped up and gave me a few options (title screen or auto play, different themes in the title, etc..).  Picked my options and 20 minutes later I had my movie on DVD. 

Very nice surprise.


I AM A PC

October 19, 2008 19:48 by ckincincy

I've done some odd things in life, but this may be the oddest!  However, I am proud to say, "I AM A PC".

Unless you've been living in a cave you have seen the ads by Microsoft. Many different kinds of people stating how they are a PC, this ad campaign is certainly in retaliation to the Mac vs. PC ad campaign. 

A buddy of mine and I go out to lunch pretty much daily (as he is a co-worker, and fellow programmer).  He was talking about his Halloween costume, dressing up as the PC guy.  And the topic of custom plates came up due to one of the owners of the company we working for recently getting a custom plate of his own.  We determined that when we got back to the office we were going to see if personalized tags were available.  Sure enough we found a few variations of the tag line that we could register.  Since it was his idea I gave him the choice of the primary one "I AM A PC" or a secondary one "IM A PC 2".  He graciously let me have the primary one, and he registered the other.  So here we are with our custom plates!

Here this week we are going to take a photo of both of us side by side and send it into Microsoft's ad campaign.

IAMAPC

IAMAPC_BOTH


Categories: .NET | ASP.NET | Microsoft
Actions: E-mail | Permalink | Comments (8) | Comment RSS

Deprecated functions in .NET

October 10, 2008 03:00 by ckincincy

When I started at my employer I inherited a bit of code that was poor at best.  Over the year I've been working with it, I've been refactoring the code significantly. 

Then we hired another developer and this process sped up a bit and I needed to mark some classes as deprecated.  So over time old code could be replaced with the new code.  I've done this before, but had to do a quick search and as an FYI here is the answer:

[Obsolete("Deprecated: Use GetCustomerID", false)]
public int GetCustomer(int custId)
{
           .... code in here

}

The first parameter is the warning/error message to show in the compiler.  The second option is whether or not to cause an error.  So basically you can say, this is broke don't use it.  Or this is old, use something else.  The first breaks the code, the second allows it to go on for a bit.

HT: Karpach.com


'.', hexadecimal value 0x00, is an invalid character. Line 1, position...

October 5, 2008 16:00 by ckincincy

Last week we upgraded our company from Sybase to SQL Server 2005.  All of a sudden one of our web applications started throwing this error:

'.', hexadecimal value 0x00, is an invalid character. Line 1, position 198128.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Xml.XmlException: '.', hexadecimal value 0x00, is an invalid character. Line 1, position 198128.

This was happening when I was calling a .NET web service via an ASPX page.  The web service call returned a serialized object:

For understanding, I have a class similar to this:

Model.Customer cust = new Customer();
cust.Id = 1;
cust.Name = "CK IN CINCY";

Now for the code that gave me this error (ie the ASPX code behind):

Model.Customer cust = new Customer();
WebSvc.GetCustomer(1, out cust);

This would blow up.

The web service looked like this:

[WebMethod]
public int GetCustomer(int Id, out Model.Customer cust)
{
     // Fill cust object from database
     return 1;
}

The problem was the data in the database contained null characters.  This is to understood as different than null records.  A null record is self explanitory and can be deal with inside the sql with an isnull call.  The problem was that the record existed but somehow has a null character.  CK IN [NULL CHARACTER] CINCY.  In this case, isnull won't solve the problem.  So after about five hours of searching I found this post.  Which contained this function, which did the trick for me.  Hopefully this saves you 5 hours of your time :-).

 

/// <summary>
/// Removes control characters and other non-UTF-8 characters
/// </summary>
/// <param name="inString">The string to process</param>
/// <returns>A string with no control characters or entities above 0x00FD</returns>
public static string RemoveTroublesomeCharacters(string inString)
{
    if (inString == null) return null;

    StringBuilder newString = new StringBuilder();
    char ch;

    for (int i = 0; i < inString.Length; i++)
    {

        ch = inString[i];
        // remove any characters outside the valid UTF-8 range as well as all control characters
        // except tabs and new lines
        if ((ch < 0x00FD && ch > 0x001F) || ch == '\t' || ch == '\n' || ch == '\r')
        {
            newString.Append(ch);
        }
    }
    return newString.ToString();

}

Nullable Int type in C#

August 18, 2008 03:00 by ckincincy

I was recently doing some development that needed to allow for an int to be null.  However in .NET that isn't allowed by default.

So I started doing some searches and found that there is a way to have nullable types in C#.

There are two ways to do this:

1. Nullable<int> x = new Nullable<int>(125);

2. int? x = 125

Now what I find interesting is how you can find out if this is null.  You can do, again, one of two things.

1. if(x.HasValue).....

2. if(x != null)....

I actually prefer option two in both situations because that just looks normal to me. 

HT: Eric Gunnerson


Quick Tip - Getting the most out of Visual Studio

August 14, 2008 03:00 by ckincincy

Great page to read to get the most out of Visual Studion.


Failed to access IIS metabase

August 10, 2008 03:00 by ckincincy

At work we've recently hired a few new developers and they got this error.

Having worked at setting up many development boxes in the past I knew what the issue was, but honestly I need to post about it so I have a quick reference to the fix... and I figured it may help you as well.

The problem?  .NET framework was installed before IIS.  The fix is pretty easy, you need to 'reinstall' the .NET framework.  Thankfully Microsoft makes it fairly easy.

Open up a command line and type the following and you will be good to go.

c:\windows\microsoft.net\framework\v2.0.50727\aspnet_regiis.exe -i

Which will look something like this after the fact:

image

More info here.


How To List All Session Variables ASP.NET

August 6, 2008 03:00 by ckincincy

Recently I needed to display all Session Variables when a crash would happen.  A crash would happen and I have this website I was working on send me an email with the stack trace and now the session variables.  However I wasn't aware of how to list all session variables, so I went to my friend Google and came up with the following code:

string strSessions;
for(int i=0;i<Session.Count;i++)
{
       strSessions += Session.Keys[i].ToString() + " - " + Session[i].ToString() + Environment.NewLine;
}

Works like a champ!

HT: davidj.org


Response.Redirect, Server.Transfer

August 2, 2008 03:00 by ckincincy

After recently launching a website, I had some built in error reporting in it.  Starting seeing a few 'Thread is being Aborted' errors.  I remembered dealing with this at my previous job and that it was related to the Response.Redirect call.

So hopefully with the help of a few of my readers we can put a list of issues related to the various calls that you can make to redirect a user to another page.

Response.Redirect
Response.Redirect was something I first used in classic ASP.  now due to the nature of that platform I didn't see any issues with it.  But in .NET its a different story.  Microsoft gives us a few versions of this call.

1. Response.Redirect("URL")  - The parameter is just the URL that you want the user sent to.  Pretty strait forward.
2. Response.Redirect("URL", true/false) - The second parameter is what causes the error above.  By default version one of this call sets the second parameter to true.  However what that does is 'abort the thread' so as your page goes down to the next call it will see that the page is being aborted.  By setting this to false, you fix the issue.  However this is not idea because by setting it to true you are getting a bit more overhead on your HTTP traffic because you are telling the server to continue the request. Even though you have moved on.

Server.Transfer
Server.Transfer is a lot like Response.Redirect in that you have two versions to call.

1. Server.Transfer("URL")
2. Server.Transfer("URL", True/False) - The second parameter determines whether or not you can use the objects (like text boxes) on the original page.  If it is set to true, you can use the objects.  If it is set to false, you can't.  Those items expire when the new page loads.

Comparisons
Now from my reading there are a few other distinct differences between the two.

1. Response.Redirect allows you to redirect to pages external to your site. The Server.Transfer HAS to be on your server.
2. Server.Transfer is just like Response.Redirect with a true passed in.  Except it doesn't throw the original error.  This allows you to save server resources as you transfer from page to page.

Well do you have anything to add?  Did I miss anything?

HT: Microsoft
HT: Karl Moore


Uninstalling .NET framework

July 21, 2008 03:00 by ckincincy

I've had two interesting things happen to friends computers over the past few months.

First I got an email from my friends at Tin Roof (by the way, if you want to support a great charity... this is it) telling me that she needed to file an extension on her taxes before she leaves for Nicaragua on Tuesday. However when she started Turbo Tax she was getting an error.

Further investigation by me (via a VNC connection I set up with her a while ago) realized that this was a .NET error.

Turbo Tax spit out the following error: 20888 39915.  A Quick search of their site gave this article.  Basically blaming .NET and their solution has a link to a program that totally wipes out .NET from your system so you can start over.  I downloaded the program, ran it and then reinstalled .NET and her problem was fixed (well after I ran a reboot.bat file that was in the Turbo Tax installation folder, but that's another issue all together).

Then I have another buddy who had been using a program I wrote for my church to transfer files between members of the multimedia team.  Several months ago a basic Windows component of it stopped working right.  I was at a total loss for a solution (as a simple uninstall and reinstall of .NET didn't help).  I let it drop... but I emailed him today with this fix and my hunch is, that this will get him up and running again.

What frustrates me the most about this, is that Microsoft's .NET uninstall doesn't fully uninstall itself.  Many years ago I did some work for Lexmark's All in One printers and one of the BIG things they did was make sure that their uninstall completely wipes out any record of the machine being on your system.  And really there is no excuse for any other behavior.