January 2006 - Posts
I have been waiting for this to be released for a very long time. This is a true designer for building XAML applications and it makes it incredibly easy to build nice looking applications very quickly. If you have installed the Windows SDK and what not, I highly recommend you download this tool and give it a try.
Microsoft Expression Interactive Designer
I have probably learned the most about XAML and the Windows Presentation Foundation (WPF formerly Avalon) by going through the Hands-On-Labs. Most of these originated at the PDC from last year. Any how, they are a great way to get familiar with XAML and they were much needed since the schema for XAML has changed significantly since these were originally released. If you have an interest in learning XAML (and you should), I recommend you check them out.
WPF Hands-On-Labs
I have already posted a few times on obsolete API calls in .NET 2.0, but I stumbled upon another list that is easier to read. In the past you had to kind of dig through a compiled help file and it wasn't really convenient to look through.
Obsolete API List: By Namespace
Obsolete API List: By Assembly
A while back I posted about how some of the better code snippets are only available for VB. Although, that was all perfectly fine for Marcus, the rest of us couldn't take advantage of these handy chunks of code. Well, Microsoft went ahead and ported all of them over to C#, so now you can take advantage of them when using C#.
There are now snippets available in the following categories. There are code snippets here to do common things such as read text from a file or ping a computer. A lot of them are pretty handy, so be sure and check them out to save yourself on some code.
- Application Code Snippets
- Collections and Arrays Code Snippets
- Connectivity Code Snippets
- Crystal Reports Code Snippets
- Database Code Snippets
- Datatypes Code Snippets
- File System Code Snippets
- Math Code Snippets
- Operating System Code Snippets
- Security Code Snippets
- Smart Devices Code Snippets
- Windows Forms Code Snippets
- XML Code Snippets
Be sure and click on the link after the group of snippets labeled click here to download all of them at once. It is a total pain in the ass to do each group seperately and I couldn't get it to work right anyway. You can find them at the URL below. Lastly after you get the snippets installed, you will have to go to the Code Snippet Manager (Ctrl+K, Ctrl+B) and add the folder where it installed them which is typically C:\Documents and Settings\<username>\My Documents\MSDN\Visual C# 2005 Code Snippets\
C# Code Snippets
A while back I posted about using aspnet_regiis to encrypt a section of a web.config. When trying this on a local machine, you will probably find that it works great. However, after deploying it I found a couple of things to look out for. First, is of course, make sure that the machine.config has a machineKey specified and it is the same across machines (including the original machine you did the encrpytion on).
I had already done that but when I tried to access the data, I found that I got the error "Failed to decrypt using
provider 'RsaProtectedConfigurationProvider'.". This is because the network service account does not have access to the keytore by default, so you have to go and grant it on each target server. To do that run the command below.
aspnet_regiis -pa "NetFrameworkConfigurationKey" "NT Authority\Network Service"
The Network Service account is the account asp.net typically runs under on Windows Server 2003. You would have to change this if you are running on Windows 2000.
After running this you shouldn't have any problem using an encrypted configuration section. If you need more help, refer to the article below from Microsoft.
How To: Encrypt Configuration Sections
Sooner or later you will probably use a GridView to do some simple data binding. The GridView is great because once you set up your SqlDataSource or ObjectDataSource (or whatever), it automatically detects the schema of your table. This is great because it allows you to databinding really easily.
There are also a number of features that let you format the data you have without writing in code. One such propery is the DataFormatString property. This property is useful for formating numbers or dates. If you are trying to format a date however, you may notice that the string you are providing is not doing anything. It took me a while to figure this out but basically this is because of HTML Encoding. In the example below, I have a data format string of {0:MM/dd/yyyy} to format my date. By default, the HtmlEncode property is set to true. To get your DataFormatString simply change it to false as shown in the image below.
I was stumbling around looking at the documentation and I stumbled upon this information in the help by accident. Basicaly, it tells you what controls you might run into issues with in trying to meet accessibility guidelines.
ASP.NET Controls and Accessibility
Puffy was always a big fan of these training CDs. Well now they are offering various titles for free. Here are some of the titles being offered.
- Exploring Visual C# 2005
- Exploring Visual Basic 2005 (Marcus probably already has this one)
- ASP.NET using Visual C# 2005
- Exploring SQL Server 2005
Free Training CD from AppDev
I was building a new form and was adding validation and I found a nice surprise. When in design mode, if you click on the ... box next to the ValidationExpression, you are prompted with the following dialog.
This editor has all the common regular expressions you might need such as E-mail Address, URL, Phone Number, and Postal Code. Who needs Marcus any more, this has almost everything you need?
Just like you can specify referneces to controls, globally, you can also use the pages element to specify a default master page so that you don't have to specify it on every page.
<configuration>
<system.web>
<pages masterPageFile="~/MasterPage.master" />
</system.web>
</configuration>
One feature not talked about very much until recently in SQL Server is the ROW_NUMBER() function. This function returns a sequential mnumber for each row returned in a resultset. With this row number you can implement data paging relatively easy. It's still somewhat complicated to understand how the basic parts work, but a query like the one will work as a good tempalte.
CREATE PROCEDRUE dbo.MyStoredProcedure
@PageIndex int,
@PageSize int
AS
BEGIN
WITH TemporaryView AS {
SELECT ROW_NUMBER() OVER (ORDER BY AnyColumn)
AS Row, Column1, Column2 FROM TableName)
SELECT Column1, Column2 FROM TemporaryView
WHERE Row between
(@PageIndex - 1) & @PageSize + 1 and @PageIndex * @PageSize
END
I want to point out the use of the WITH statement above. There is something new in SQL Server 2005 called Common Table Expressions (CTE). These effectively let you dynamically create a virtual view. So what the fire statement does is assigns a row number to everything in the table and creates a virtual view that the next statement can select from. Although ASP.NET 2.0 has built in paging features with the GridView, etc. It is not suitable for large amounts of data because all of the paging is done on the web server. This method of writing a stored procedure will probably become a best practice for paging with large amounts of data because it only grabs the rows it needs at the SQL Server level.
I am getting where I can't keep up with these CTPs. Anyhow, this version is getting closer and closer to beta. In fact, they now have go-live licenses now for Windows Communication Foundation and Windows Workflow Foundation (nothing for Windows Presentation Foundation yet unfortunately). The other key thing it adds is that the "Cider" XAML designer has now been integrated into Visual Studio. This is basically the same designer that will be using in Microsoft Sparkle so it should be a lot easier to do XAML applications.
As usual, you need to uninstall any previous versions first. This page has a link to everything that you need.
WinFX January CTP
If you are using a lot of XSL Transformations and have migrated to ASP.NET 2.0, then there are some significant preformance gains to be had by making a few simple code changes. The XslTransform class is now considered obsolete and has been replaced with XslCompiledTransform. This class on averages performs transformations four times faster than XslTransform. Basically it is supposed to be on par to using MSXML 4.0 directly.
It's syntax is roughly the same as using XslTransform. Unless you are using some of the more obscure parameters with XslTransform, you can pretty much do a straight refactor nad it should compile and work. If XSL performance has ever been an issue, I recommend making the change as soon as possible.
The link below contains detailed information on it from Microsoft's XML Team.
XslCompiledTransform
Although creating a class outside of a namespace is probably considered bad form, in .NET 2.0 there is actually a way to access it.
namespace Blah
{
class Class1
{
public void MyMethod()
{
// reference using the global keyword
global::Class2 myClass2 = new global::Class2();
myClass2.MyMethod();
}
}
}
public class Class2
{
public void MyMethod()
{
// do something
}
}
You will notice that Class2 is not included in the namespace of blah. Before, it would be rather difficult to make a call to that class. It might not have even compiled, I am not sure. Well, now with the use of global::, you are able to make a call to that class.
I have more included this information, not because you will use it, but in case you run into it some place in the future.
Also if you are wondering where else you have seen global::, it is also used in the reference.cs of web services inside class libraries.
global:: used in Web Service Proxies
This isn't really .NET 2.0 related or anything, but I still think it might be useful. I don't know how many times I have been charged with a task of importing data from a text file or from an access database or whatever and I ran into an issue where the supposed primary keys have duplicate rows in them. Well, with the aid of google, I found a relatively easy way to find the duplicates using the HAVING SQL clause.
The query below, will spit out the values committing the offense against the primary key. You may need to import your data to a temp table in SQL first without a key set. It will also work directly in Access.
SELECT COUNT(*), PrimaryKeyColumn
FROM TableName
GROUP BY PrimaryKeyColumn
HAVING Count(*) > 1
That's all there is to it. If you have a compound primary key, you can find it in a similar way.
SELECT COUNT(*), PrimaryKeyColumn1, PriamryKeyColumn2
FROM TableName
GROUP BY PrimaryKeyColumn1, PrimaryKeyColumn2
HAVING Count(*) > 1
That's not .NET related, but I hope it helps you out someday.
More Posts
Next page »