Wednesday, March 25, 2009
The Browser Wars Rage On
Monday, March 23, 2009
Sports drinks and regular exercise
- Electrolytes are solutions of acids or salts
- They help the body conduct motor control electrical signals
- Electrolytes are gradually lost during exercise
- Only intense and extended exercise requires extra electrolyte replishment
- Extreme exercise without replishment may result in overhydration
Saturday, March 21, 2009
Buying PC parts
- http://en.wikipedia.org/wiki/Contrast_ratio
- http://en.wikipedia.org/wiki/Digital_Visual_Interface
- http://en.wikipedia.org/wiki/Vga
- http://en.wikipedia.org/wiki/Response_time_(technology)#LCD_monitors
- http://www.crucial.com/systemscanner/index.aspx (inspects your memory for you)
- http://en.wikipedia.org/wiki/Hdmi
- http://en.wikipedia.org/wiki/Dsub
- http://www.crucial.com/uk/
- http://www.ebuyer.com/
- http://www.novatech.co.uk/
- http://www.europc.co.uk/ (discount, but very good, DELLs)
- http://www.scan.co.uk/ (heavy on the postage - not my favourite any more)
- http://www.microdirect.co.uk/
Thursday, March 19, 2009
Getting the correct month, no matter the country
How to be productive...
Wednesday, March 18, 2009
Totally Awesome - Real Digital Paper!
Tuesday, March 17, 2009
Monday, March 16, 2009
Sunday, March 15, 2009
Microsoft links I have yet to read, but really should...
Using Conditions?
How Do I: Create a Breakpoint Using Hit Count?
How Do I; Learn Tips and Tricks for Debugging in Visual Studio?
Office Development with Visual Studio Developer
Center Just Launched!
Microsoft Cloud Computing Tools
How Do I: Add Tool Windows to the Visual Studio IDE?
How Do I: Add a New Tool Window to Visual Studio?
How Do I: Integrate With the Error List?
How Do I: Create a Basic Language Service Using the Managed Babel System?
How Do I: Create Custom
Project Templates Using Visual Studio 2008?
How Do I: Create an Item Template Using Visual Studio 2008?
How Do I: Write to the Output Window?
Explore the New Features of Visual Studio 2008
How Do I: Create a Debugger Visualizer?
How Do I: Place My Commands Into Different Kinds of Visual Studio Menus?
How Do I: Add Commands
and Controls Into the Visual Studio IDE?
How Do I: Get Started with the VisualStudio Domain Specific Languages?
Heroes Happen Here
DotNetNuke® and Visual Studio 2008
Visual Studio Tip of the Day
How Do I: Add AJAX Functionality to an Existing ASP.NET Page?
How Do I: Debug a Windows Presentation Foundation Application in Visual Studio 2008?
How Do I: Use the LINQ-Enabled
XML API in Visual Studio 2008?
Some bluetooth resources. Rage.
Gizmodo, gadgets and fun in the news...
Friday, March 13, 2009
Tips 'n' Tricks - Null Coalescing Operator
Really we just want to do this:
public class Something
{
private string falafel;
public string GetInfo()
{
return falafel ?? "tabbouleh";
}
}
But then falafel doesn’t get set.
This feels inelegant:
if (falafel == null)
falafel = "tabbouleh";
return falafel;
Luckily, there’s a solution:
return falafel ?? (falafel = "tabbouleh");
This first sets the value of falafel and then returns it.
Wednesday, March 11, 2009
Fun With GridView...
Anwyay, todays subject, minor though it is, is GridView commands...
...I wanted to have a grid with a couple of buttons: Up and Down, as link buttons, to re-order my content without an edit button.
The solution is simple enough:
- Add a Button column to your GridView
- Set it's 'button type' to Link (this is optional really)
- In the GridView's events panel, double-click RowCommand
- In the generated event handler you can place:
switch (e.CommandName) { .... }
Simple really.
Lastly, here's some resources I've been looking at recently:
- http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand.aspx
- http://weblogs.asp.net/scottgu/archive/2005/10/18/427754.aspx
- http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/ASPNETProvMod_Prt5.asp
- http://www.ondotnet.com/pub/a/dotnet/2005/01/10/liberty.html
- http://www.odetocode.com/Articles/440.aspx
- http://www.asp.net/QuickStart/aspnet/doc/profile/default.aspx
- http://www.theserverside.net/tt/articles/showarticle.tss?id=CreatingProfileProvider
- http://flimflan.com/blog/ProfileView.aspx
- http://weblogs.asp.net/scottgu/archive/2006/01/10/435038.aspx
- http://www.asp.net/sandbox/samp_profiles.aspx?tabindex=0&tabid=1
- http://msdn2.microsoft.com/en-us/library/83y98ckk.aspx
- http://www.google.com/search?hl=en&lr=&q=aspnet_regsql+command-line+utility+&btnG=Search
- http://www.learnvisualstudio.net/
- http://www.asp.net/learn/absolute/default.aspx?tabid=63
- http://www.microsoft.com/uk/msdn/security/link_library.mspx
- http://weblogs.asp.net/scottgu/archive/2006/04/13/Source-Code-for-the-Built_2D00_in-ASP.NET-2.0-Providers-Now-Available-for-Download.aspx
- http://weblogs.asp.net/scottgu/archive/2006/02/24/438953.aspx
Caching and Url Mapping
If you look at the line <%@ OutputCache... in the .aspx files you will see that it is configured to cache the output of that whole page for the value in the Duration attribute. The VaryByParam value indicates that any url parameter will cause the page to be re-generated and cached. Replace the "*" with "none" and the caching will ignore the url params and that page will be cached once for the duration.
The OutputCache can be used in individual user controls as well, however, if the page has a duration of 20 and the control within it has a duration of 10 both will be cached for 20. Reverse those numbers and the page will be cached for 10 but the control will be cached for 20.
Be careful that you don't try to reference in your code a control which may have been cached, as it will come back with a null reference, possibly causing an exception!
One other method of caching is substitution mapping, the drawback being that you can only point this at .net controls, not user controls.
Url Mapping.
Now, go to IIS, create a virtual directory under Default Web Site, point it at the Test solution's directory. Open the Properties panel for the virtual dir. Do the following:
Disable directory browsing.
Under Documents, enable default document and have only 1 default document called default.aspx.
Go back to Virtual Directory, click Configuration, click Add and enter:
1. Executable: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
2. Extension: .*
3. All Verbs
4. Script Engine ticked
5. Check that file exists NOT ticked
6. Click Ok, Click Ok.
Go to ASP.NET tab and ensure the ASP.NET version is 2.0.50727
Click Ok.
Now, when you browse to http://localhost/test/lose/ or http://localhost/test/win/ you should see the page come up which is actually /test/win.aspx or /test/lose.aspx. Hit refresh and you will see the time has not changed, because the page has been cached. The page appears, even though you have entered a directory name, because IIS is automatically adding default.aspx to any requested directory listing and redirecting all file requests to the .net framework. The .net framework is redirecting from ~/win/ or ~/lose/ to ~/win.aspx or ~/lose.aspx because in the web.config you have a UrlMapping block! Easy.
The only problem with this is that you can't use regular expressions to have, for example, ~/search/ipod/ re-mapped to ~/search.aspx?query=ipod which is annoying, but only because the next server version from microsoft will have a fully operational url mapper and they didn't have time to put it into the current release.
Links:
Caching: http://msdn2.microsoft.com/en-us/library/xsbfdd8c.aspx
Substitution mapping: http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.substitution(VS.80).aspx
Url Mapping: http://www.developer.com/net/asp/article.php/3581326
MS Blog: http://weblogs.asp.net/scottgu/archive/2005/11/14/430493.aspx
Tuesday, March 10, 2009
Tools List
- http://validator.w3.org/feed/
- Brass - Dynamic
- Windows Enhancement
- Kris' blog - VB.NET & C# comparison cheat sheets
- Fiddler Web Debugger - Freeware HTTP(S) debugging tool
- Time And Date .com
- Recuva - Undelete, Unerase, File Recovery - Builds
- regsitry cleaner
- dale lane » Blog Archive » Twitter for Windows Mobile
- http://aspnetresources.com/tools/keycreator.aspx
- XE.com - The World's Favorite
- Currency Site
- fiddler
- Free Virus Scan - Kaspersky Lab
- Dapper: Feed Generator
- Core Temp
- UNLOCKER 1.8.7 BY CEDRICK 'NITCH' COLLOMB
- Fences™ Community Preview Download - By Stardock - Clean
- up your ...
- Feed
- Validator for Atom and RSS
- http://www.dictionary.com/
- Elias Fotinis DeskPins :: Make Any Window Topmost
- Quick Media
- Converter
- ITUNES TOOLBOX: 30+ Tools For iTunes
- MD5 Generator
- Restoration Freeware download and review - file undeleteutility ...
- home of the nerd cave - Taskbar Shuffle
- http://www.coveritlive.com/index.php
- Say NO to 0870
- reCAPTCHA: Stop
- Spam, Read Books
- Crystal Dew World - Software - CrystalDiskInfo
- Launchy: The Open Source
- Keystroke Launcher
- VB.NET to C# Converter
- Freecorder audio recorder
- Free Online PDF viewer - PdfMeNot.com
- PAYPAL - ipn payment simulator
- MaxiVista - Multi Monitor Software
- YouTube Video Download Tool
- Online free Windows Icon creator
- SandCastle - Code Documentation Generator
- http://www.quickonlinetips.com/archives/2005/03/great-flickr-tools-collection/
- http://www.itagsoftware.com/index.php
- http://www.wingrep.com/download.htm
Rubberduck Debugging
We called it the Rubber Duck method of debugging. It goes like this:
1) Beg, borrow, steal, buy, fabricate or otherwise obtain a rubber duck (bathtub variety)
2) Place rubber duck on desk and inform it you are just going to go over some code with it, if that's all right.
3) Explain to the duck what you code is supposed to do, and then go into detail and explain things line by line
4) At some point you will tell the duck what you are doing next and then realise that that is not in fact what you are actually doing.
The duck will sit there serenely, happy in the knowledge that it has helped you on your way. Works every time. Actually, if you don't have a rubber duck you could at a pinch ask a fellow programmer or engineer to sit in.
Monday, March 09, 2009
ASP.NET Life Cycle Diagram
Creating a certificate in IIS
- IIS Resources Toolkit download: http://www.microsoft.com/downloads/details.aspx?FamilyId=56FC92EE-A71A-4C73-B628-ADE629C89499&displaylang=en
- IIS Resources help page: http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/993a8a36-5761-448f-889e-9ae58d072c09.mspx?mfr=true
- Google search for IIS resources information: http://www.google.com/search?hl=en&rlz=1C1CHMB_en-GBGB316GB316&q=iis+resources&btnG=Search
- At a command prompt, switch to the "C:\InetPub\AdminScripts" folder.
- Type the following command:
CSCRIPT ADSUTIL.VBS SET W3SVC/DisableSocketPooling TRUE
C:\>cd InetpubC:\Inetpub>cd AdminScriptsC:\Inetpub\AdminScripts>CSCRIPT ADSUTIL.VBS SET W3SVC/DisableSocketPooling TRUEMicrosoft (R) Windows Script Host Version 5.6Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.DisableSocketPooling : (BOOLEAN) TrueC:\Inetpub\AdminScripts>
Augmented Reality in CSharp
http://www.mperfect.net/wpfAugReal/
- DirectShow API on WikiPedia: http://en.wikipedia.org/wiki/DirectShow
- DirectShow Article at CodeProject: http://www.codeproject.com/KB/directx/directshownet.aspx
- TotalImmersions AR video: http://video.google.com/videoplay?docid=6523761027552517909
- Also, a skeleton C# AR app: http://sites.google.com/site/augmentedrealitytestingsite/
Thursday, March 05, 2009
ASP.NET Globalization, Culture, Localization and the Resource tag
In addition to programmatic access, ASP.NET 2.0 also introduces declarative syntax you can use to bind a named string to a property of a page or control. The syntax involves using the dollar sign ($) followed by the Resources namespace, the name of the resource file and the name of the string:
Wednesday, March 04, 2009
Tweet tweet tweet...
Commerce Server, Afraid to ask?
http://blogs.msdn.com/maxakbar/search.aspx?q=pipeline+afraid&p=1
gacutil exited with error 9009
Tuesday, March 03, 2009
Quake? Online? In a browser window? Nice(?)
http://www.hanselman.com/blog/QuakeLiveReviewAndRantWhyIsThisInteresting.aspx
Thursday, February 19, 2009
Convert byte[] to String
I was going to make one big entry containing lots of little bits of code, then realised I only had one to put in, because I keep forgetting it...
Converting a byte[] (array) into a String:
string outStr = System.Text.Encoding.UTF8.GetString(inByteArr);
Thursday, February 12, 2009
More useful links...
I have posted many links on this blog, for many reasons. I'll now be posting even more. These are useful .NET coding resources which I simply don't want to forget.
TRULY UNDERSTANDING VIEWSTATE:
http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/Truly-Understanding-Viewstate.aspx
TRULY UNDERSTANDING DYNAMIC CONTROLS (PART 1):
http://weblogs.asp.net/infinitiesloop/archive/2006/08/25/TRULY-Understanding-Dynamic-Controls-_2800_Part-1_2900_.aspx
Building Templated Custom ASP.NET Server Controls:
http://msdn.microsoft.com/en-us/library/aa478964.aspx
Developing Custom ASP.NET Server Controls:
http://msdn.microsoft.com/en-us/library/zt27tfhy.aspx
Introducing Commerce Server 2007:
http://www.microsoft.com/commerceserver/default.mspx
Max akbar - For the hardcore Commerce Server Developer... and demystify the product:
http://blogs.msdn.com/maxakbar/
Getting Started with Windows Communication Foundation (WCF):
http://msdn.microsoft.com/en-us/netframework/aa663324.aspx
Windows Presentation Foundation:
http://en.wikipedia.org/wiki/Windows_Presentation_Foundation
Using Bluetooth in .NET:
http://dotnet.org.za/rudi/archive/2007/09/28/using-bluetooth-in-net.aspx
Search JQuery from inside Spotlight:
http://www.appelsiini.net/2009/2/search-jquery-api-docs-from-spotlight
Mozilla's new cloud-based HTML editor:
http://www.readwriteweb.com/archives/bespin_html_editor_cloud.php
Simon Edwards' blog:
http://www.transceiver.co.uk/
Adobe Photoshop Express:
https://www.photoshop.com/express/landing.html
CoolIris media viewer (see top of page):
http://www.cooliris.com/
What annoys you about Windows?:
http://www.annoyances.org/
YouTube tools:
http://www.quickonlinetips.com/archives/2006/10/the-amazing-youtube-tools-collection/
Friday, January 23, 2009
More Embedded Resource fun
If you're new to embedded resources please read this entry first: http://springboardpillow.blogspot.com/2009/01/embedded-resources-and-having-fun-with.html
Now we'll use the same image, from my previous blog entry, from within the project we created earlier. For this we will need a...
Custom Web Control
To make this, either use the default ServerControl1.cs, or right click the control project and select: Add -> New Item -> Web -> ASP.NET Server Control. By default this should give us:
WebCustomControl1.cs
To get in the habit, first...
Compile the Control Project
Select: Build -> Rebuild [project name]
This will recompile the custom web control project, including the new (empty) control and place it's DLL into the web project. This is because we previously referenced the control project from the web project. Now, we are going to...
Add a reference to the Embedded Resource to the Custom Control
In the new custom control, find the RenderContents(...) method and replace it's content with:
output.Write(
"<img src='"+
Page.ClientScript.GetWebResourceUrl(typeof(EmbeddedCtrls.ServerControl1),"EmbeddedCtrls.cartman.jpg")+
"' />"
);
You should be able to see that this is essentially just manually writing out the same code as was in the previous web page, however this time we are inside the custom control and so the reference to it can essentially be 'this.GetType()'.
Now, rebuild the custom control project as before (Build -> Rebuild [project name]) and the updated DLL will be copied to the web project. All we need to do is...
Drop the Custom Control onto a Web Page
So, create a new ASPX in the web project and open it's design view. If the custom web control project compiled correctly, you should have a new toolbox group called '[project name] Components'.
Grab the custom control from within the toolbox group and drop it onto the designer. Save everything and run the page.
You should now have the same output as in the previous blog entry!
Easy, eh?
Two things to Note are...
That dropping the custom control on your web page add a Register directive to the top (just as any ASP.NET toolbox control does)
And that you will have a <span> tag surrounding your <img> tag. To remove this, simply override RenderBeginTag and RenderEndTag, like so:
public override void RenderBeginTag(HtmlTextWriter writer)
{
// removed one line of default code!
}
public override void RenderEndTag(HtmlTextWriter writer)
{
// removed one line of default code!
}
Listing the Known Embedded Resource
If you want to place a stop point in your code and list the embedded resource files that are available to you, paste the following line just before your stop point:
object a = GetType().Assembly.GetManifestResourceNames();
Upon stopping here, the 'a' object will be a list of embedded resources.
As Before...
The entire demo solution can be found here.
Resources:
http://support.microsoft.com/kb/910442
http://www.codeproject.com/KB/aspnet/MyWebResourceProj.aspx
http://aspnet.4guysfromrolla.com/articles/080906-1.aspx
http://aspalliance.com/726
http://msdn.microsoft.com/en-us/library/yhzc935f.aspx
Embedded Resources and having fun with them
Ok, so, having gotten back from 2 months round the world and almost 3 months not coding at all, I'm feeling rusty. Opening Visual Studio came as quite a shock, simply because "All Those Buttons Can't Possibly Do What I Remember!!!"
Anyway, back in the saddle (I hope) and getting some new code under my belt: This time in the form of...
Embedded Resources
What are those? Well, when you drop, say, a GridView control or something, anything from the toolbox onto your page and it already has, lets say, stylesheets, images, javascript etc, that you think would be better provided as separate files... they probably are. How? Well, when building the code as separate files the non-C# files are placed into an...
ASP.NET Server Control project
This project then needs to be referenced by the web project, so that it's DLL is placed in the website's \bin directory, thus placing any (correctly compiling) custom web controls [because that's what this project type is for] into the toolbox (when ASPX/ASCX 's are in design mode.)
So, lets...
Create a Custom Web Control with images and stylesheets in a DLL
So, open Visual Studio and create a new solution (File -> New -> Project -> Visual C#|Basic -> ASP.NET Web Application) This will give us a website as well.
Now, to this solution, add an ASP.NET Server Control project (File -> Add -> New Project -> Visual C#|Basic -> Web -> ASP.NET Server Control) This gives us a project we can create custom web controls in. This is also the project where the embedded files will be placed.
Ok, so the quickstart to adding and using an embedded resource is...
Add an Embedded Resource and call GetWebResourceUrl
First we need something to use. So lets add an image to the control project - not the web project!
In order to make the image embedded select it in the solution explorer and in the properties panel change it's Build Action to Embedded Resource.
Now make the image usable by expanding the control project's Properties item (in the solution explorer) and edit the AssemblyInfo.cs. Add the following lines to the using declarations at the top:
using System.Web.UI;
And the following to them bottom:
[assembly: WebResource("EmbeddedCtrls.cartman.jpg","image/jpg")]
Where the format is:
[assembly: WebResource("[assembly name].[directory names].[filename]","[filetype]")]
For an image called "cartman.jpg" stored in the root directory of the control project.
Bear in mind that the first part is the assembly name (select the project in solution explorer and click properties) and not the namespace. Also, that rather than being a typical absolute path, the path separators are '.' and not '/'.
We now have a project with an image which can be referenced as an embedded resource, both by code within the control project and any project which references it's DLL's, eg: the web project we created at the start.
Important: One major stumbling block I found was that if the above line of code, in the AssemblyInfo.cs, does not get recognised by Visual Studio, it means something has gone when creating the project. Just delete it and create a new "ASP.NET Control Project". It should appear as so:
[assembly: WebResource("EmbeddedCtrls.cartman.jpg","image/gif")]
Or something close to that, assuming you haven't adjusted your editor styling.
Now, to actually use this image somewhere, we need to...
Add a reference to the Control Project and Compile It.
So, in the web project, right click the References and add the control project as a reference. Then, select the control project in the solution explorer and click Build -> Build [project name]
This will compile the control project and copy it's DLL into the web project's \bin directory. Nearly there. Finally, we need to use it by...
Adding a reference in a web page
Either add an ASPX or open the default one. Paste the following line into the <div></div> statement in the HTML of the page:
<img src='<%= Page.ClientScript.GetWebResourceUrl(typeof(EmbeddedCtrls.ServerControl1),"EmbeddedCtrls.cartman.jpg") %>' />
And run the web page. If everything goes to plan, you should have a page with a single img tag which displays your embedded image.
If WebResource.axd is not found, check the highlighting of the assembly: webresource statement as described above. Also, check that the image file Build Action is set to Embedded Resource, in the properties panel. If the image simply fails to appear, just go through and check that you are providing the correct file name, assembly name, etc.
If you get a web resource exception, it's because you are not registering the embedded resources correctly. If you get a webresource.axd?d=... URL but it shows nothing, it's because the image file is not being referenced in your code properly. The GetWebResourceUrl call and the AssemblyInfo.cs entries must match.
Failing the above, ensure that each time you change the contents of the control project that you rebuild the project and refresh the web page. Simply recompiling the web project will not do it (unless you've configured your solution especially - this is not the default in VS.)
Wasn't that fun? You can download the complete solution here. That is also the same download for the next blog entry, where I will deal with referencing the image from within the control project.
Resources:
http://support.microsoft.com/kb/910442
http://www.codeproject.com/KB/aspnet/MyWebResourceProj.aspx
http://aspnet.4guysfromrolla.com/articles/080906-1.aspx
http://aspalliance.com/726
http://msdn.microsoft.com/en-us/library/yhzc935f.aspx
Saturday, October 04, 2008
Getting MVC setup
This is all about getting MVC Preview 5 running: http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=16775
ASP.NET Project page: http://www.asp.net/mvc/
Had a bit of trouble getting MVC setup. A nasty little bugger going by the name of "Cannot load assembly ..." etc. You know the score.
One post on forums.asp.net sorted it all out:
http://forums.asp.net/p/1314519/2596828.aspx
I short, do the following:
Go to: C:\Documents and Settings\All Users\Start Menu\Programs\Microsoft\Microsoft Visual Studio 2008\Visual Studio Tools
Run: Visual Studio 2008 Command Prompt
Go to: C:\Program Files\Microsoft ASP.NET\ASP.NET MVC CodePlex Preview 5\Assemblies
Type:
C:\Program Files\Microsoft ASP.NET\ASP.NET MVC CodePlex Preview 5\Assemblies>gacutil -if System.Web.Routing.dll
And:
C:\Program Files\Microsoft ASP.NET\ASP.NET MVC CodePlex Preview 5\Assemblies>gacutil -if System.Web.Abstractions.dll
That should install the DLL's into the GAC (Global Assembly Cache) and cause .NET 3.5 to find them suitably.
Thursday, August 28, 2008
Release Mode missing
I recently realised, after a long time of not caring, that there are two ways to create a web project, with only one allowing Release Mode compilation.
Release Mode allowed: File -> New -> Project -> Visual C# -> Web -> ASP.NET Web Application
Only Debug Mode allowed: File -> New -> Website
Of course, from the command line, both of these options are available, as the options taken when creating any project are simply preset instructions for the compiler switches.
However, I feel it's important to note that only in Release Mode can the source of the website be compiled into a single DLL.
Reference: http://forums.asp.net/p/1053679/1532732.aspx#1532732
Friday, June 20, 2008
Getting ASP.NET Authentication in SQL Working
Firstly, you could go here, which helped me: http://weblogs.asp.net/scottgu/archive/2005/08/25/423703.aspx
Otherwise, just go to: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
Run the aspnet_regsql.exe and following through the Next button.
If you want to setup a connection to your local machine running sql express, be sure to enter <machinename>\<sqlserver> for example: MATTSMACHINE\SQLEXPRESS
Everything should now be setup.
The next bit is optional, but I like to go to: http://msdn.microsoft.com/en-us/library/cc467894.aspx
Get the latest build of the Microsoft Enterprise Library. The setup is fairly simple, just install and follow the instructions for setting up the web.config and connection strings for allowing the data access layer. This will provide easy to use connection pooling and everything you need for single command SQL execution on your db.
The important entries in your web.config file should be:
<configSections>
<section name="dataConfiguration"...
...
</configSections>
<connectionStrings>
<add name="chopDatabaseConnection" providerName="System.Data.SqlClient"...
...
<dataConfiguration defaultDatabase="chopDatabaseConnection"/>
And you're away!
You might also want to read this:
Friday, May 23, 2008
Slapdash - Putting feeds on your page the easy way
I wanted to read RSS into a DataSet but found that when loading the XML from, for example, a community server feed I would often get a 'column already exists'. This was because the feed used namespaces which causes elements to be declared like this: <slash:comment>
There are two solutions to this. First, write an XSLT to parse out the stuff I don't want. Second, run over the raw XML myself and filter it. I wanted to go with the second, because writing XSLT for every customised RSS, ATOM, etc feed that my front end developers might want to use didn't appeal - I just wanted to be able to load the RSS into a DataSet. However, then I found some code which seemed to work: http://www.aspcode.net/Updated-RSS-reader-class-dealing-with-already-belongs-error.aspx
The one problem I had was that the code did not seem to know when an element like <enclosure/> did not have a closing tag following it. I have fixed this code and present it below. I have used it to load the header information and each item entry in the RSS feed into a couple of repeaters, for quick databinding, so that I can provide a simple data layout for my front end designer to work with. He can then style this anyway he likes and I can even wrap the items table in a DataView to sort and filter it by any combination of fields in the feed. Of course, because this uses a DataSet, I could even merge other feeds into it.
Many thanks to, er, admin(?), for writing the original - you really have helped me a lot!...
protected void Page_Load(object sender, EventArgs e)
{
DataSet set = new DataSet();
XmlTextReader xmlRdr = new XmlTextReader("http://stuff.tv/blogs/cool/rss.aspx");
XmlDocument doc = new XmlDocument();
doc.Load(xmlRdr);
set = GetRSSDataSet("http://stuff.tv/blogs/cool/rss.aspx");
headerRepeater.DataSource = set.Tables[1];
itemsRepeater.DataSource = set.Tables[2];
DataBind();
}
public DataSet GetRSSDataSet(string m_strAdress)
{
DataSet m_ds = new DataSet();
System.Xml.XmlTextReader oXml = new System.Xml.XmlTextReader(m_strAdress);
oXml.WhitespaceHandling = System.Xml.WhitespaceHandling.None;
System.Text.StringBuilder oBuilder = new StringBuilder();
bool fContinue = oXml.Read();
while (fContinue)
{
string sName = oXml.Name.Replace(":", "_");
bool isClosed = oXml.IsEmptyElement;
if (oXml.NodeType == System.Xml.XmlNodeType.Element)
{
//Add the element...
oBuilder.Append("<" + sName);
if (oXml.HasAttributes)
{
while (oXml.MoveToNextAttribute())
{
sName = oXml.Name.Replace(":", "_");
oBuilder.AppendFormat(" " + sName + "=\"" + oXml.Value + "\"");
}
}
if (isClosed)
oBuilder.Append("/");
oBuilder.Append(">");
}
else if (oXml.NodeType == System.Xml.XmlNodeType.Text)
{
oBuilder.Append(System.Web.HttpUtility.HtmlEncode(oXml.Value));
}
else if (oXml.NodeType == System.Xml.XmlNodeType.EndElement)
{
oBuilder.Append("</" + sName + ">");
}
fContinue = oXml.Read();
}
oXml.Close();
string sXmlResult = oBuilder.ToString();
m_ds = new DataSet();
System.IO.StringReader oStringReader = new System.IO.StringReader(sXmlResult);
try
{
m_ds.ReadXml(oStringReader, System.Data.XmlReadMode.Auto);
}
catch (Exception ex)
{
m_ds = null;
}
if (oStringReader != null)
oStringReader.Close();
if (oXml != null)
oXml.Close();
return m_ds.Tables.Count == 0 ? null : m_ds;
}
[EDIT: 2008-06-20] I have a .NET3.5 new and improved version of this, which allows multiple feeds and optional sorting - I'll post this later.[EDIT: 2009-02-19] Sorry for not having posted the replacement of this code. I will, when I find it. A lot has happened since the original posting.
Tuesday, April 01, 2008
How to Auto-Create Stored Procedures
Use this script. I make no guarantees on it's solidity, but it has been useful. It will try to execute the CREATE PROCEDURE commands it executes, so comment those out if you want to run them manually.
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- Author: Matthew Webster
-- Create date: 2007-03-20
-- Description: Automatically creates stored procedures for insert, update and delete functions
ALTER PROCEDURE [dbo].[Cms_CreateAuto_Procs]
@author nvarchar(250),
@tableName varchar(8000)
AS
BEGIN
SET NOCOUNT ON;
--declare @tableName nvarchar(50)
--set @tableName = 'editorialtypegroup'
--declare @author nvarchar(50)
--set @author = 'Matthew Webster'
declare @insert varchar(8000)
declare @update varchar(8000)
declare @delete varchar(8000)
declare @key varchar(8000)
declare @fields varchar(8000)
declare @arguments varchar(8000)
declare @variables varchar(8000)
declare @assignments varchar(8000)
set @key=''
set @fields=''
set @arguments=''
set @variables=''
set @assignments=''
select @key=@key+ ', '+column_name
from information_schema.columns
where table_name=@tableName and (COLUMNPROPERTY(OBJECT_ID(@tableName), column_name, 'isidentity') = 1) AND (column_default IS NULL)
select @fields=@fields+ ', '+column_name
from information_schema.columns
where table_name=@tableName and (COLUMNPROPERTY(OBJECT_ID(@tableName), column_name, 'isidentity') = 0) --AND (column_default IS NULL)
select @arguments=@arguments+ ', @'+column_name+' '+data_type+'(' + cast(character_maximum_length as varchar(10)) +')' + case is_nullable when 'no' then ' ' when 'yes' then '=null' end
from information_schema.columns
where table_name=@tableName and (COLUMNPROPERTY(OBJECT_ID(@tableName), column_name, 'isidentity') = 0) and character_maximum_length<>null AND (column_default IS NULL)and data_type<>'text'
select @arguments=@arguments+ ', @'+column_name+' '+data_type
from information_schema.columns
where table_name=@tableName and (COLUMNPROPERTY(OBJECT_ID(@tableName), column_name, 'isidentity') = 0) -- and (character_maximum_length=null or data_type='text' ) AND (column_default IS NULL)
select @variables=@variables+ ', @'+column_name
from information_schema.columns
where table_name=@tableName and (COLUMNPROPERTY(OBJECT_ID(@tableName), column_name, 'isidentity') = 0) --AND (column_default IS NULL)
select @assignments=@assignments+ ', '+column_name+' = @'+column_name
from information_schema.columns
where table_name=@tableName and (COLUMNPROPERTY(OBJECT_ID(@tableName), column_name, 'isidentity') = 0) --AND (column_default IS NULL)
set @key=SUBSTRING(@key,3,len(@key))
set @fields=SUBSTRING(@fields,3,len(@fields))
set @arguments=SUBSTRING(@arguments,3,len(@arguments))
set @variables=SUBSTRING(@variables,3,len(@variables))
set @assignments=SUBSTRING(@assignments,3,len(@assignments))
/*--
select @tableName
select @key
select @fields
select @arguments
select @variables
select @assignments
*/
declare @insertProc varchar(8000)
set @insertProc = '
CREATE PROCEDURE Cms_Auto_Insert'+@tableName+'
'+@arguments+'
AS
BEGIN
SET NOCOUNT ON;
insert into '+@tableName+' ('+@fields+') values ('+@variables+')
END
;
'
declare @updateProc varchar(8000)
set @updateProc = '
CREATE PROCEDURE Cms_Auto_Update'+@tableName+'
@'+@key+' int, '+@arguments+'
AS
BEGIN
SET NOCOUNT ON;
update '+@tableName+'
set '+@assignments+'
where '+@key+' = @'+@key+'
END
;
'
declare @deleteProc varchar(8000)
set @deleteProc = '
CREATE PROCEDURE Cms_Auto_Delete'+@tableName+'
@'+@key+' int
AS
BEGIN
SET NOCOUNT ON;
delete from '+@tableName+' where '+@key+' = @'+@key+'
END
;
'
exec (@insertProc)
exec (@updateProc)
exec (@deleteProc)
END
How to Stack Trace SQL
Just use SQL Profiler - if it's installed! Open the profiler, connect to a database, File->New. Remember to check the boxes for text query and hit run. Let your code do it's bit, then hit stop. But be quick about it, because there's probably a lot of other stuff going on and (like C# debugging) this could all come jumping out you in a very short space of time.....
Friday, January 11, 2008
Useful MSDN Blog Links and Immutable Classes
The standard feed provided in the Visual Studio 2005 Start Page provides some very useful links. One of them is this:
a blog tutorial on creating immutable classes and the clever things to do with them.
I'm hoping to build a large list of really useful links featured on that feed, here.
Yes, yet another list.
MicroSoft Visual Source Safe
This is just a little post to lament the problems provide (as features) by VSS. Fortunately, this guy has posted them already: http://www.highprogrammer.com/alan/windev/sourcesafe.html
Happy coding...
Thursday, January 10, 2008
SubSonic and some DAL stuff
So I've been using CodeSmith with NetTiers for over a year now and loving almost every minute. However, there is now a very large problem which seems to have settled in and won't go away, like an elephant in the corner at a party. Except that everyone is talking about how to get rid of it, but no-one's managing to shift the thing. This problem is that Deep-Loading and Deep-Saving cannot be guaranteed in any version. (My personal issue with this is that if a nightly release does appear with a fix, any number of other critical bugs arise to replace it.) So, what we have is a DAL (Data Access Layer) generator which used to be wonderful and cuddly, but is now more of a problem than the number it solves.
So, what am I doing about it? Helping to solve the code issues? Submitting a new series of DAL templates using a radical and effective new code schema? Or ignoring the problem entirely?
That's right, I'm leaving my rather large application using the last, most reasonable generated DAL layer as it is, until I find another DAL generator I can use. Obviously, this is because there's a lot of people with much more experience solving their own code bugs without me trying to hack their templates apart. While I feel a little guilty about jumping ship, I will quite happily throw my support behind them if this quite annoying bug gets solved - something which used to be a huge selling point, IMHO.
Anyhow, this situation has opened a number of avenues. Among them is a little thing called SubSonic, with the catchy slogan "All Your Database Are Belong To Us!" Nice.
I'm only just starting with this one, so I've no useful (or other) information to pass on, so I'll start with some links and hopefully, soon, there'll be plenty of musing from my addled brain...
http://geekswithblogs.net/dlussier/archive/2007/12/30/118069.aspx
http://geekswithblogs.net/scottkuhl/archive/2006/11/17/97470.aspx
http://subsonicproject.com/view/for-web-sites---using-the-buildprovider.aspx
http://www.codeplex.com/subsonictools
http://blog.benhall.me.uk/2007/10/setting-up-subsonic.html
http://www.scribd.com/doc/94319/SubSonic?query2=%27SubSonic.Generated.+does+not+contain+a+definition+for
Saturday, November 03, 2007
ReOrderList replacement and other AJAX.NET Fun
Having gotten fairly annoyed with the flaky-ness of the AJAX.NET ReOrderList control (among others) I've decided to take a look at building my own. Having had a look at a really great tutorial on javascript drag and drop code:
http://www.webreference.com/programming/javascript/mk/column2/
I've built a couple of custom controls; DragItem and DragContainer. These are part of an in-dev solution I'm building to provide myself (and anyone bothered enough to read on) with lightweight AJAX controls. Mostly because I want to understand the intricacies of this black magic, but partly because I believe the javascript libraries provided by the AJAX Toolkit to be too heavy for inidividual control use.
To justify myself here: I love the Ajax Control Toolkit and think MS are doing a brilliant job, especially when there are kits like:
http://www.telerik.com/
out there. But, and this is big, the dynamically provided javascript libraries which the API requires each browser page to download (assuming the ScriptManager control is placed) are too big. I want a small piece of script, perhaps placed within the page, rather than a seperate file, to perform efficient, fast actions, not replace most of the js API in the browser and watch/handle a million things I'm probably not even aware are going on. Not that I mind those features being there when they're needed!
Anyway, here's a list which might be useful to some:
http://ajaxpatterns.org/DotNet_Ajax_Frameworks
And here's the solution download for my own .NET AJAX controls:
http://home.freeuk.com/eudoxus/JsWebSite.rar
Saturday, October 06, 2007
UnbindablePanel
To download the example solution click here: http://home.freeuk.com/eudoxus/JsWebSite.rar
[EDIT 03/11/2007] This link has been changed to include the code provided in my most recent Ajax-oriented post: ReOrderList replacement and other AJAX.NET Fun
I've been trying to get a Repeater to bind it's DataSource to contained controls for differing content. What I mean, there, is that if the DataSource has objects of different type I want to render a different data binding within the ItemTemplate depending on the type of data in the current DataItem. [Skip the next two paragraphs to get to the interesting bit.]
Having failed to try this by forcing Panel, PlaceHolder, MultiView/View and Wizard/StepTemplate from binding in anything other than a straightforward way (I hate it when future me can't follow younger me code!) I decided to try my latest trick...
Ok, I can't believe I didn't realise this before (or perhaps a more obvious solution - which, no, I still haven't discovered), but inheritting Panel and adding or overriding to get the functionality you want is just about the best way to make accessible, functional custom controls! They have data containers, can be bound, are supported by VS GUI and everyone understands them.
So, the situation is thus; I have bound a Repeater to a DataSource which provides an enumeration of objects which have different properties. This could be a random collection of DateTime, String and DataRow objects, or anything. Don't ask why, I just want to do it.
My solution is, essentially, to make a Panel which will not bind it's child controls if told not to. To decide whether it should or not, we simply check the class type, an identity or type field, property or namespace, etc.
So, first we inherit the Panel control:
public class UnbindablePanel : Panel
Then we have to provide a property which will determine whether or not the child controls found within the Panel will be databound:
private bool _allowChildBinding = true;
public virtual bool AllowChildBinding
{
get
{
return _allowChildBinding;
}
set
{
_allowChildBinding = value;
}
}
And finally, override the DataBindChildren() method to avoid the databinding if needed:
protected override void DataBindChildren()
{
if (AllowChildBinding)
{
base.DataBindChildren();
}
}
There is a little extra; in order to ensure the Panel is not visible at all, you might want to include a property/method combo to ensure the visibility matches the databound true/false value. This would stop any non-databound controls from being seen, but as such, is not absolutely necessary and is not the driving force behind this class.
To download the example solution click here: http://home.freeuk.com/eudoxus/JsWebSite1.rar
Thursday, October 04, 2007
Very Useful Utils
Trucking about ye olde net recently, I've found (and been pointed at) some very useful utilities. Here are the blogged lists I've seen;
Ultimate Developer and Power Users Tools for Windows
Essential Developer Productivity Tools
Austin Harris - some HTML tools
And here's my list;
Beyond Compare - File Content and Directory Structure Comparison Tool
FlyAKite - Make Windows look like MacOS
MobyDock - MacOS style icon bar
Microsoft Power Toys - Toys from MS for Windows
Task Tips - Not downloads per se, but useful none-the-less
30 Pieces of Essential Software
Remote Desktop Tricks - Again, not a download, but useful
Install multiple versions of IE
Forgot Admin password?
Some windows and filing utils
Microsoft's own Windows Internal Tools
A better Task Switcher
TopDesk - New ways to switch windows
Zoom effects for opening icons and folders
Visual Task Tips - Thumbnails for your TaskBar icons
Free tools - including pixel ruler and currency converter
If anyone has any more, please comment...
Thursday, July 12, 2007
Finally got Microsoft Bluetooth Generic and ActiveSync working again!
Prologue:
(1) Disabled Microsoft ActiveSync to stop my mobile synchronising every time I wanted to charge it.
(2) Updated all software via Windows Update, including Bluetooth drivers.
Synopsis:
(1) ActiveSync refused to work again, even with repeated un-installs and re-installs.
(2) My ePox BT-DG03 Bluetooth USB Dongle stopped working because the latest Microsoft Bluetooth drivers are now called ABE Bluetooth Controller and don't work with it (these replaced the previous Windows XP SP2 bluetooth drivers "Generic Bluetooth Radio" and "Microsoft Bluetooth Enumerator".)
Today:
(1) Took a complete, clean copy of my C:\Windows\Inf, C:\Windows\System32 and all sub-folders onto my iPod and brought them in.
(2) Uninstalled ActiveSync and all associated Bluetooth drivers (Add/Remove Programs and Device Manager.)
(3) Connected Device via USB cable; Machine should recognise Generic RNDIS device and ask for drivers, etc.
(4) PLugged-in bluetooth dongle; Machine should again recognise bluetooth device and ask for drivers, etc.
The Secret:
When drivers are asked for;
(1) Un-install all the existing device drivers to avoid conflicts.
(2) From device manager, perform Update Drivers.
(3) Select "Install from a list or specific location (Advanced)."
(4) Select "Don't search. I will choose the driver to install."
(5) Click "Have disc".
(6) Browse to your backed-up copy of C:\Windows\Inf and select the file "drvindex.inf".
(7) From then on it should find the correct devices and all you have to do is show it where to find the right files.
I had to do this 2 or 3 times before the driver installs stuck, but now it's fairly happy and I can just plug the dongle and mobile phone in and no more reinstalls need to take place.
The key files I found are:
Bluetooth Device;
(1) rfcomm.sys (system32\drivers)
(2) wshBth.dll (system32)
(3) irftp.exe (system32)
(4) irmon.dll (system32)
Standard Modem over Bluetooth link;
(1) bthmodem.sys (system32\drivers)
Be warned, there are more files the auto-installer will ask for, but if/when I need to do this again, I'll try and note them all down.
Epilogue:
(1) I've had one instance where the bluetooth dongle needed to be reinstalled, but with care and forethought, the right drivers can be picked - this is down to selecting Show All Devices (when the option is presented) and always selecting \Inf\drvindex.inf, to give the auto-install the best chance of finding the right driver.
Saturday, July 07, 2007
iTunes Remote Control
Ok, for those interested enough, there's a log window, which shouldn't dump out too much; volume controls work, but there's a bug in that once a volume or position value gets changed, messages start getting thrown back and forth- Once I've re-worked the request and response formats I'll be fixing the synchronisation issues. The format issue will also allow the playlist window to function by feeding from partial list messages.
There is also an iPod look-a-like dialog, which will in time provide full control. This will be waiting until after the other functions/bugs have been sorted out.
You can download the current version here: http://home.freeuk.com/eudoxus/BtChat.2007-07-07.001.rar
Again, thanks to everyone on the 32feet.net forums who helped!
Matt.
Thursday, July 05, 2007
Bluetooth iTunes Remote for Windows Mobile 5.0
[EDIT] This has no changed to: http://home.freeuk.com/eudoxus/BtChat.2007-07-07.001.rar
Please see post for update: http://springboardpillow.blogspot.com/2007/07/itunes-remote-control.html
In theory, I've got the whole thing working:
Queued message sending (from the client) to avoid blocking the BT device
Threaded timer updates of the display
Error log dialog
Back/Next/Play/Pause/Volume/Time controls
Track/Artist/Album display
The problem I'm facing right now is that bluetooth has completely failed on my work machine and I'm finding that the only drivers which work are the Generic Bluetooth Radio and Microsoft Bluetooth Enumerator - which should be one driver and are ONLY available via Windows Update - and of course have now been replaced by a broken driver called ABE.
To add to the fun threading seems to lock up when I kick off my own thread on the device side of the application, as if the two threads used for monitoring in-coming messages are the only threads I'm allowed to run. I'm not sure, but I think it might be the BtListener thread which is causing problems, however the forums say otherwise.