Love This!

SharePointDev

Tags: ,

WPF Checked ListBox

WPF currently does not have a checked list box out of the box so you’ll need to roll your own. Unfortunately most of the examples that come up on Google involve creating a usercontrol and writing some code.

Here’s one quick way that does not not involve writing any additional code.

Step 1: Start off by creating a class that will represent each checked list item in the list box. Obviously if you already have your data item all you need to ensure is that it has a boolean property to store the Checked/Unchecked flag.

public class CheckedListItem
{
    public int Id { get; set; }
    public string Name { get; set; }
    public bool IsChecked { get; set; }
}

 

Step 2: Create the list item that will be bound to the list box. I called my list AvailablePresentationObjects.

public List<CheckedListItem> AvailablePresentationObjects;

Step 3: The last step is to create the actual checked list box. I created a list box and used the HierarchicalDataTemplate to hold the CheckBox. The Name and the IsChecked property are then bound to the checkbox.

<ListBox ItemsSource="{Binding AvailablePresentationObjects}" >
    <ListBox.ItemTemplate>
        <HierarchicalDataTemplate>
            <CheckBox Content="{Binding Name}" IsChecked="{Binding IsChecked}"/>
        </HierarchicalDataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

And walla!

WPF-CheckedListBox

Now the IsChecked property will reflect the value in the UI and vice versa. If you need real-time notification when someone checks/unchecks then you simply need to raise the PropertyChanged event in the CheckedListItem class.

Tags: , ,

The War is Over

Sri Lanka is finally rid of the terrorists, the war is over. I hope and pray that we have seen the end of senseless bloodshed.

Let’s build a better, peaceful Sri Lanka.

Tags:

Fixing the Silverlight caching issue

Fell into this trap today. I deployed an update of my silverlight project to the Sharepoint site but on some machines the browser continously kept loading the older version.

I racked my brain trying to figure out how to add ETags to a xap file and yet keep the deployment simple. The answer though is unbelievably simple in this case. Update your AssemblyVersion when compiling. That’s it. IIS takes care of sending the update through to all the browsers.

BTW the silverlight.net forums are a gem for figuring out answers to silverlight problems.

Tags:

Changing the default schema in Oracle

The application I was working on assumed that the user would always be in the default schema. I ran into a snag when I had to connect to the staging environment where the read only user that I was provided with didn’t have all the objects in his schema.

The solution was to make a call to change the default schema using the ALTER SESSION call with this code.

        /// <summary>
        /// Sets the schema to use if one is configured.
        /// </summary>
        public static void SetSchema()
        {
            var schema = ConfigurationManager.AppSettings["SchemaName"];
            if (string.IsNullOrEmpty(schema)) return;
 
 
            using (var connection = GetConnection())
            {
                using (var command = new OracleCommand("alter session set current_schema=" + schema))
                {
                    connection.Open();
                    command.Connection = connection;
                    command.ExecuteNonQuery();
                }
            }
        }

Tags: , ,

Date Ranges in Log Parser for EventLogs

If you need to trawl through your production server event logs. Here’s a quick tip for extracting just the entries for a given date range using LogParser. BTW Visual LogParser is a must have, it even downloads and automatically installs the latest version of LogParer from MS.

SELECT  TimeGenerated, SourceName, ComputerName, Message FROM C:\Downloads\May09-ErrorLog\AppLog\*.evt
WHERE TimeGenerated BETWEEN timestamp(‘04/04/2009′, ‘dd/MM/yyyy’) and timestamp(‘06/04/2009′, ‘dd/MM/yyyy’)
ORDER BY TimeGenerated desc

Tags: , , ,

Making your portable hard disk work with the XBox 360

I like using my XBox as a media center. But when I plugged in a portable HDD to the 360 but it didn’t show up as a disc. Didn’t work on the Samsung home theatre as well. A quick google and I figured out the disc was formatted as NTFS (right-click Properties on your drive to check) on which is not supported by the 360.

Okay so backed up the data and when I try to format as FAT32 there is no such option on the Explorer ‘Format’ dialog. It’s either NTFS or exFAT, couldn’t figure out if the 360 supported exFAT (should have tried) so went about trying to format from the command line. Which does have a switch for FAT32.

Unfortunately format.exe complains that the partition is too big. What I should not have done was to try a quick format.

Instead I went about deleting the partition as mentioned by several sites. There’s a good one built into Windows (Disk Management) that you can get through from ‘Computer Management’. So right-clicked on the external disc and did a ‘Delete Volume’. And then right-clicked and created a new volume. [NOTE: I think the whole delete and create a new volume can be skipped if you already have the partition in NTFS).

Next tried the format.exe again. Still fails complaining that the disc is too big. At whim tried formatting without the /Q (quick format) option. Worked fine.

Here’s how you would go about it (replace Q: with the drive letter of your portable disc).

C:\>format Q: /FS:FAT32

Tags: , , ,

Show Folder Tree in Windows 7 Explorer

I spend a lot of my time switching between folders in Windows explorer and the Windows 7 explorer has been driving me nuts lately.

Win7 (or at least the build I have) by default does not auto expand the tree view when you navigate between folders.

The result being you don’t see the usually tree hierarchy on the left pane. Which makes it quite painful if you want to go up a few levels or see the other parent folders.Windows7-Explorer

Luckily there is a new Folder Option called Navigation Pane to switch them back on again. You need to press Alt + T or Organize –> Folder Search Options in Windows Explorer to get to the dialog. Windows7-FolderOptions

Switch both of them on and viola I get my beloved tree view back.

Windows7-Explorer-Expanded 

PS- Most of my UW colleagues use other explorers and didn’t have to feel this pain.

Microsoft .NET Framework 3.5 SP1 breaks Microsoft CCF (Customer Care Framework)

So your seeing this exception in your WCF client application after installing SP1 on .NET Framework 3.5

System.ServiceModel.Security.MessageSecurityException occurred Message="The HTTP request is unauthorized with client authentication scheme ‘Negotiate’. The authentication header received from the server was ‘Negotiate

As described in this bug report Microsoft classifies this as a known issue, with the bug being resolved as ‘By Design’.

Your fix is to add an identity element to the WCF endpoint like this.

<identity>
    <userPrincipalName value="WcfServiceAccount@domain" />
</identity>

But the problem with CCF is that the url for some of the endpoints are read through code from a database and set through the proxy class. Now when you do this the identity from the config file does not flow through resulting in the same exception you see above.

One option is to uninstall the service pack on the client. This is not as easy as it seems because the the 3.5 service pack also updates assemblies in the 2.0 and 3.0 frameworks to their SP2 levels.

To get back to pre 3.5 SP1 you need to uninstall all the frameworks and re-install them again avoiding the 3.5 SP1. The exact steps to do this is outlined here by Microsoft engineer, Aaron Stebner.

But what if you don’t have the luxury of walking all your end-users through the uninstall? A suggested fix from Microsoft (targeting CCF) is as follows:

  1. Set up a cNAME in DNS for the servername you are using in database urls.
  2. Use setspn -a HOST/CNAME domain\apppooluser
  3. Change all the database urls to this CNAME
  4. Do an iisreset
  5. Test

For example if the database urls are http://ccfserver/…..

  1. Create a  CNAME CCFALIAS in DNS
  2. setspn -a HOST/CCFALIAS ccf\aspuser
  3. Change all database urls to ccfalias
  4. iisreset
  5. Test if you reach /urls with this alias from web servers and from clients

Be careful not to set HOST/CCFSERVER spn for aspuser. Note we are setting HOST/CCFALIAS spn which is CNAME for ccfserver in DNS. If by mistake you set host/ccfserver it can wreak havoc  for Kerberos.

Tags: , ,

Another Dell XPS M1330 tip: External Display Flicker

Although five of us have exact same setup, I am the only one at work to experience the external display flickering. I tried everything from downloading all the latest updates from the dell site, mucking around with all the display options to no avail. I even plugged in my XPS to a couple of my colleagues displays (in high hopes of stealing it if it worked) but no, it had to flicker for my laptop. Whereas they would happy go about their merry day with a crystal clear and crisp display while I looked on enviously.

I finally got fed up today when the flickering worsened and asked Google again, “why me?” and Google replied “You are not alone”, the only problem was that I had to go through Google cache as Dell seems to have pulled the plug on this particular page.

Thankfully Brandon (aka GadgetPhreak) had found a workaround and posted it way back in Dec 07, here’s what he says.

I purchased an XPS M1330 configured as follows:

  • SYSTEM COLOR: Tuxedo Black
  • PROCESSOR: Intel® Core™ 2 Duo Processor T7500 (2.2GHz/800Mhz FSB, 4MB Cache)
  • OPERATING SYSTEM: Genuine Windows Vista™ Business Edition
  • LCD AND CAMERA: Slim and Light LED Display with VGA Webcam
  • MEMORY: 3GB Shared Dual Channel DDR2 at 667MHz
  • HARD DRIVE: Speed: 160GB SATA Hard Drive (7200RPM)
  • INTERNAL OPTICAL DRIVE: CD/DVD burner (DVD+/-RW Drive)
  • VIDEO CARD: 128MB NVIDIA® GeForce™ 8400M GS
  • WIRELESS CARDS: Intel Next-Gen Wireless-N Mini-card
  • BLUETOOTH AND WIRELESS USB: Built-in Bluetooth capability (2.0 EDR)
  • BATTERY OPTIONS: 6 cell Primary Battery and 9 cell additional Lithium Ion Battery
  • SOUND OPTIONS: ExpressCard Sound Blaster X-Fi® Xtreme Audio Sound Card
  • FINGERPRINT SCANNER: Biometric Fingerprint Reader

I attempted to connect it to the same external monitor used with my XPS 1210 (a 20" Viewsonic VX2025wm LCD with a native resolution of 1680×1050) and where I used to get a crisp, clean, flicker-free image with my M1210, I now get a lot of screen flicker.

I did some research and found someone running a similar type of LCD who had better luck with using an HDMI to DVI-D adapter and ran it into the DVI input on his monitor.  However, that didn’t work for me.

In trouble shooting this I found something interesting, when I remove AC power to my laptop while connected to the Viewsonic, the flickering stops.  When I reconnect it the flickering starts up again.  This is true regardless of what resolution I am running on either the laptop or Viewsonic.  I went through the advanced power settings and tried looking for differences for when the AC is plugged in vs. when it’s running on battery.  I also tried re-installing video drivers, as well as the latest Nvidia drivers from Dell downloads.  Nothing has resolved this yet.

Suggestions?

Thanks in advance,

Branden

 

And behold I pulled out my power cable and the flickering stopped! Now I’m off to customer support to see if I can get an HDMI to DVI cable ;)

Tags: , ,

Archives