.Net ramblings
# Friday, 05 January 2007
Code 39 error on DVD drive in Vista...
all of a sudden my dvd drive stopped working, and i couldn't figure out why.  there was no drive listed in explorer and the device was not working, code 39.  i eventually found this ms kb article that gets you to delete 2 registry settings to fix the problem.  they said it could be caused by installing Easy CD Creator.  i tried to uninstall AsusDVD and that may have done it.  in any case, it works now.


Friday, 05 January 2007 17:27:30 (GMT Standard Time, UTC+00:00)  #    Comments [1]  General

# Tuesday, 19 December 2006
Global hotkeys with Windows Media Player / Vista
WMP 11 isn't so bad, but the big criticism of WMP all along is that it doesn't support global hot keys like winamp does.
enter "WMP Keys" from sourceforge.  It runs like a champ and does the job, using Ctrl-Alt-Right Arrow for next track, Left for previous track etc.  you need to register the plugin dll, and when i ran it from the command prompt first of all, it didn't succeed.  you need to register it with admin privilege, to do this right click the command prompt in the start menu and run it as administrator. 


Tuesday, 19 December 2006 12:29:37 (GMT Standard Time, UTC+00:00)  #    Comments [4]  General

# Wednesday, 29 November 2006
Problems with the AJAX AutoCompleteExtender (arrgh)
I was interested to see that Atlas/AJAX has now made it to Beta 2.  I looked at it earlier in the year but didn't have time to really get stuck in.  So today i eventually got it working in conjunction with LINQ.  I wanted to get a basic AutoComplete thing working off my database, with which i am hopefully going to use LINQ throughout.

First of all, go to http://ajax.asp.net/ and download and install the 3 bits they recommend. 

Getting the darn thing to work

Brad Adams has a very good getting-started example on this post, i used his article as a starting point, but i had to sort out a few other things first.  i couldn't get any documentation on the AutoCompleteExtender so i scavenged some crucial facts off the net after a lot of fumbling around, i've listed these below.  One mistake i made was to start testing the AutoComplete control before making sure that the web service was returning correct data, my LINQ query was chucking exceptions and the AJAX control doesn't give you any feedback on exceptions, which is understandable and probably desirable.
  • you must mark your web service class with the [ScriptService] attribute, you'll need the Microsoft.Web.Script.Services namespace for this.
    [WebService(Namespace = "http://whatever")]
    [ScriptService]
    public class AjaxService : System.Web.Services.WebService
    {
  • you need two parameters in your web service method, the naming of the parameters is crucial:
    [WebMethod]
    public string[] GetList(string prefixText, int count)
  • if you're using Linq, and if you're new at it like me, you might have trouble getting your LINQ query results into a string array for the web service.  I tried returning IEnumerable<TableName> and List<string> etc. but it didn't like that, i ended up using the ToArray() extended method that is part of System.Query.  Here is the query i used which concatenates some columns from the table into a collection of strings. 
    IEnumerable<string> ds =
                from r in MyDataBase.Restaurants
                where r.RestaurantName.Contains(prefixText)
                select (r.RestaurantName + "," + r.Address1 + "," + r.County); // join the name + address in a string
    string[] results = ds.ToArray<string>();
    return results;

Formatting the AutoCompleteExtender

The control has some nasty hard-coded values, but where there's a will there's a way.  Thanks to the Firefox dom inspector and the CSS !important modifier, all is not lost. 

The control does have a property called CompletionListElementID which specifies the container element where the results are inserted.  I put a simple DIV next to the textbox:
<div id="AutoComplete" runat="server"> </div>
Then in my stylesheet i have the following values to override the hard-coded styles set by the control:
#AutoComplete
{
    width: auto !important;   
    overflow: visible !important;
}
#AutoComplete div
{
    font-size: x-small !important;   
}
In case you're wondering, the control renders each result as a DIV inside your specified element.  The control applies the following styles to your specified element:
border: 1px solid buttonshadow; 
overflow: hidden;
visibility: visible;
background-color: window;
color: windowtext;
cursor: default;
width: 130px;
position: absolute;
left: 184px;
top: 27px;
display: inline;

You can override whichever ones you want by applying the !important attribute inside the #AutoComplete entry in the style sheet.  The individual items then can also be styled via the #AutoComplete div entry, i prefered a slightly smaller font size because the default setting looked too big.


Wednesday, 29 November 2006 16:54:25 (GMT Standard Time, UTC+00:00)  #    Comments [4]  Asp.Net

# Tuesday, 10 October 2006
A generic Swap function
if i ever forget how to write this function then... well, let's hope i never do.  i was really surprised not to be able to find it in the SDK.  i'm posting it here for reference anyway.  note: this can only be used in .Net 2.0 which supports generics.
/// <summary>
/// Swap 2 objects
/// </summary>
public static void Swap<T>(ref T first, ref T second)
{
T tmp = first;
first = second;
second = tmp;
}


Tuesday, 10 October 2006 16:55:31 (GMT Daylight Time, UTC+01:00)  #    Comments [3]  .Net General

# Saturday, 07 October 2006
HowTo: Deploy Crystal Reports for VS 2005
i found this insanely difficult because none of the supposedly normal options worked.  merge modules didn't seem suitable because i just wanted to install the CR dlls once and for all on the server.  according to an MSDN2 article i should be able to perform a windows installer deployment, but of course when i copy the key code from the VS2005 > Help > About dialog, and use it in the installer on the server, the error message is that the key code has expired or is invalid.  'business objects' appear to be forcing users into an upgrade path for their new product, by claiming that a 'compatibility upgrade' is required for VS 2005, which of course you have to fork out for.  such a load of crap. 
anyway, what eventually worked for me was to go back into my VS 2005 dev machine and create a web set up project. go into the project properties and click the prerequisites button, select CR for .Net 2.0 and then just build the empty setup project. if you look in your output folder, there is an installation file called CRRedist2005_x86.msi.  Just whack this onto the server and your crystal reports should run fine, i didn't need to reboot or restart IIS.  Note there is no also need to copy any of the CR dlls to your web site bin folder. 

yet another miserable failure for crystal reports!


Saturday, 07 October 2006 01:32:30 (GMT Daylight Time, UTC+01:00)  #    Comments [1]  .Net General | Asp.Net | Windows Server

# Thursday, 05 October 2006
HowTo: Automate SQL Express Backup
There is a thoroughly excellent article about this on the SQL DBA Tips web site.  Don't forget to enable modify permissions for the account that is running SQL Express, e.g. Network Service.
just posting it here in case i ever forget where it is.


Thursday, 05 October 2006 11:31:25 (GMT Daylight Time, UTC+01:00)  #    Comments [1]  Database

# Friday, 08 September 2006
Handy Excel Tip to Show Duplicate Entries
http://office.microsoft.com/en-us/assistance/HA011366161033.aspx


Friday, 08 September 2006 14:42:58 (GMT Daylight Time, UTC+01:00)  #    Comments [0]  General

# Wednesday, 06 September 2006
FIX: VS2005 Unrecognised tag prefix or device filter
I encountered this error after upgrading a web site to VS2005 and converting it to a Web Application Project.  the project built without problems, it was just the designer kept throwing up errors in the error list which was very annoying.

Thanks to 'ratureus' for his post on http://forums.asp.net/thread/1212425.aspx

  • Close VS 2005
  • delete all files in C:\Documents and Settings\yourusername\Application Data\Microsoft\VisualStudio\8.0\ReflectedSchemas\
  • Restart VS 2005
this worked for me. 


Wednesday, 06 September 2006 11:50:04 (GMT Daylight Time, UTC+01:00)  #    Comments [0]  Asp.Net

# Tuesday, 05 September 2006
PDF problems: File does not begin with %PDF
I use exported crystal reports in PDF format on my web site, and i was getting intermittent errors from a small number of users.  I couldn't reproduce it, and i found a thoroughly excellent article on the problem at the Fluid Components International web site. 

They explain what's going wrong and have some suggestions to fix it.  I suspect in my case it was a problem with embedding the PDF in an activeX control.  i'll just redirect users to download the file instead. 

Tuesday, 05 September 2006 15:29:49 (GMT Daylight Time, UTC+01:00)  #    Comments [0]  Asp.Net

# Wednesday, 30 August 2006
A javascript function to enable MaxLength behaviour for Multiline Textboxes
http://www.dynamicdrive.com/dynamicindex16/maxlength.htm

<script type="text/javascript">

/***********************************************
* Textarea Maxlength script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)
}

</script>


<textarea maxlength="40" onkeyup="return ismaxlength(this)"></textarea>


Wednesday, 30 August 2006 17:12:43 (GMT Daylight Time, UTC+01:00)  #    Comments [0]  Asp.Net