 |
|
 |
|
|
|
"Atlas" gets a Name |
|
Andy's Blog
|
By Andy Beaulieu on
9/12/2006 6:49 AM
|
|
|
|
... from a post by Scott Guthrie where he also estimates the v1.0 release "around the end of this year."
1) The client-side “Atlas” javascript library is going to be called the Microsoft AJAX Library. This will work with any browser, and also support any backend web server (read these blog posts to see how to run it on PHP and ColdFusion).
2) The server-side “Atlas” functionality that nicely integrates with ASP.NET will be called the ASP.NET 2.0 AJAX Extensions. As part of this change the tag prefix for the “Atlas” controls will change from <atlas:>to <asp:>. These controls will also be built-in to ASP.NET vNext.
3) The “Atlas” Control Toolkit today is a set of free, shared source controls and components that help you get the most value from the ASP.NET AJAX Extensions. Going forward, the name of the project will change to be the ASP.NET AJAX Control Toolkit.
|
 |
|
Comments (0)
|
|
|
|
ReportViewer Control - Customization at Runtime |
|
Andy's Blog
|
By Andy Beaulieu on
8/30/2006 7:14 AM
|
|
|
|
Let's say you just created a really cool Report for the .NET 2.0 ReportViewer Control (well, as cool as a report can be anyway).
But wait... At runtime, you want to examine and maybe even change attributes of the report. Like column names, labels, etc.
How do we get at Report properties at runtime?
One way is to tweak the RDLC (Client Report Definition) file before it is fed to the ReportViewer Control. RDLC is based on XML, so we can use XPath queries to find and tweak RDLC properties.
There is a post here that describes this method, and another example below.
First we create a utility function to load in the RDLC and tweak or examine it as necessary...
private TextReader GetCustomRDLC(string rdlcSource)
{
TextReader readerReport;
XmlDocument xmlReport = new XmlDocument();
Stream streamReport;
streamReport = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(rdlcSource);
xmlReport.Load(streamReport);
XmlNamespaceManager nsManager = new XmlNamespaceManager(xmlReport.NameTable);
nsManager.AddNamespace("dns", "http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition");
XmlNodeList nodes = xmlReport.SelectNodes("//dns:Table[@Name='table1']//dns:Details//dns:Textbox", nsManager);
foreach (XmlNode node in nodes)
{
System.Diagnostics.Debug.WriteLine(node.Attributes["Name"].Value);
}
return new StringReader(xmlReport.OuterXml);
}
... then we can use this function to feed the ReportViewer Control...
// create a datasource for the report and set to the datatable dt1
ReportDataSource rds = new ReportDataSource();
rds.Name = "DataSet2_Employees";
dt1.DefaultView.Sort = "FirstName";
rds.Value = dt1.DefaultView;
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(rds);
reportViewer1.LocalReport.LoadReportDefinition(GetCustomRDLC("ReportViewerTest.Report2.rdlc"));
reportViewer1.RefreshReport();
|
 |
|
Comments (0)
|
|
|
|
Marshaling a Byte Array to COM object |
|
Andy's Blog
|
By Andy Beaulieu on
8/25/2006 7:05 AM
|
|
|
|
I have been helping someone port a Delphi app to WindowsForms and we ran into something interesting. The Delphi app uses a 3rd-party ActiveX control to display spreadsheets. Unforunately, the ActiveX control has not been ported to .NET, and the Delphi app stores the spreadsheet control data as a proprietary format BLOB in the database.
The ActiveX control had documentation for the method we needed to call:
Syntax ReadFromBlob hBlob, nReservedBytes
Part Type Description hBlob OLE_HANDLE Reference to a BLOB variable in memory. nReservedBytes Integer Size of the BLOB variable. Not implemented in this version and must be 0.
So, after adding the ActiveX control to WindowsForms, how to feed it these bytes? We need to create an unmanaged buffer to hold the data and get that to the method. We can use AllocCoTaskMem of the Marshal class to allocate the unmanaged buffer and then marshal it to the ActiveX control...
// assume we have a byte array inside byteData read from DB. int size = byteData.Length; IntPtr buffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(size) * size); Marshal.Copy(byteData, 0, buffer, size); int ptr = buffer.ToInt32();
// now we can feed the control myControl.ReadFromBlob(ptr, 0);
Marshal .FreeCoTaskMem(buffer);
|
 |
|
Comments (2)
|
|
|
|
Where is my Profile object? |
|
Andy's Blog
|
By Andy Beaulieu on
8/1/2006 8:15 AM
|
|
|
|
Profiles are supposed to be easy in ASP.NET 2.0. You just add a section in your web.config like so:
<profile defaultProvider="CustomizedProfileProvider">
<providers>
<add name="CustomizedProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="MyConnectionString" applicationName="/MyApplicationName" />
< SPAN>providers>
<properties>
<add name="MySetting" type="int16" defaultValue="10" />
< SPAN>properties>
< SPAN>profile>
... after which ASP.NET 2.0 generates a nice strongly typed class for you so you can access your settings like so:
short x = Profile.MySetting;
Unfortunately, the strongly typed class is generated into your App_code folder. And if you have happened to use the VS2005 Web Application Projects Add-in, you won't have an App_code folder, which means you won't have access to the Profile strongly typed object.
There are two ways around this problem that I know of:
(1) there is another add-in called the WebProfile Generator just for these circumstances.
(2) if you can live with "loosely typed" Profile access, you can just code against a ProfileBase instance like so:
ProfileBase profile = ProfileBase.Create(Membership.GetUser().UserName);
short newSetting = 42;
profile.SetPropertyValue("MySetting", newSetting );
profile.Save();
|
 |
|
Comments (0)
|
|
|
|
ApplicationException is old school?! |
|
Andy's Blog
|
By Andy Beaulieu on
7/27/2006 6:24 PM
|
|
|
|
This is an odd change on a Microsoft "best practice..." For .NET Framework v1.x, it was recommended that you always inherit from ApplicationException when creating custom exception classes for your application.
But for Framework 2.x, they have revoked this recommendation, as you can see here...
For most applications, derive custom exceptions from the Exception class. It was originally thought that custom exceptions should derive from the ApplicationException class; however in practice this has not been found to add significant value.
I'm not sure why they made this distinction? ApplicationException is inherited from Exception anyway, and I can't imagine there is significant performance issues there? Anyone? Bueller?
|
 |
|
Comments (0)
|
|
|
|
Some miscellaneous stuff |
|
Andy's Blog
|
By Andy Beaulieu on
7/6/2006 5:41 PM
|
|
|
|
web.config Encryption "Can't I encrypt portions of my web.config so people can't just pop that file open and find my db passwords and other sensitive stuff?" ASP.NET 2.0 has expanded support for config section encryption, and this article gives a good overview of using aspnet_regiis to do just that.
Drawing Primitives using JavaScript After all the iterations of the web browser, isn't it funny how we still can't do things like draw simple shapes?! Don't worry, there is always a kluge. Until Vector Markup Language is supported in more browsers, we can use this LGPL javascript library to draw simple shapes.
|
 |
|
Comments (0)
|
|
|
|
Notes for VB.NET Class |
|
Andy's Blog
|
By Andy Beaulieu on
6/14/2006 12:44 PM
|
|
|
|
Here are a couple of notes for the VB.NET class I instructed at this week...
(1) Creating a global exception handler for WindowsForms (.NET 1.1): This is a multistep process (note that in .NET 2.0 they give you a global exception handler in Project properties which is nicer). Create a Sub Main module that creates your main form and adds a handler for the Application.ThreadException. In Project Properties, change your startup object to Sub Main. (code below)
Module SubMain
Public Sub main()
Try AddHandler Application.ThreadException, AddressOf HandleExceptionEvent
Dim frmMain As New Form1 Application.Run(frmMain)
Catch ex As Exception HandleException(ex)
End Try
End Sub
Private Sub HandleExceptionEvent(ByVal sender As Object, ByVal e As System.Threading.ThreadExceptionEventArgs)
HandleException(e.Exception)
End Sub
Private Sub HandleException(ByVal ex As Exception)
MsgBox("Sorry, an error has occurred:" & ex.Message)
End Sub
End Module
(2) Creating a TextBox class that handles Enter as Tab key: some users prefer hitting ENTER on each WindowsForms field to "tab" to the next field. We can do this by creating an inhertied textbox and handling its KeyPress event. First create a new Class and then implement as follows
Public Class TextBoxEnterTab Inherits TextBox
Private Sub TextBoxEnterTab_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
If e.KeyChar = Chr(13) Then
SendKeys.Send("{TAB}") e.Handled = True
End If
End Sub
End Class
(3) Code Generation Tools: Check out MyGeneration dOOdads and CodeSmith
(4) Miscellaneous tools and utilities for development VBCommenter - generates comment blocks for VB.NET http://www.gotdotnet.com/team/ide/
NDoc - generates documentation automatically form XML comments http://ndoc.sourceforge.net
NET Reflector - used to disassemble assemblies http://www.aisto.com/roeder/dotnet/
REGEXLIB - an online Regular Expression library to use with the Regular Expression Validator controls http://www.regexlib.com
Enterprise Library - Microsoft's Application Blocks for handling common development tasks http://www.microsoft.com/downloads/details.aspx?familyid=5A14E870-406B-4F2A-B723-97BA84AE80B5&displaylang=en http://msdn.microsoft.com/library/?url=/library/en-us/dnpag2/html/EntLib2.asp
Atlas http://atlas.asp.net - Microsoft's AJAX library, including Behaviors
|
 |
|
Comments (0)
|
|
|
|
Deploying ReportViewer Control |
|
Andy's Blog
|
By Andy Beaulieu on
5/19/2006 4:07 PM
|
|
|
|
So you've created a cool new WindowsForms Smart Client Application that uses the ReportViewer control, and it's time to deploy it. There is an article here that explains how to use the ReportViewer.exe redistributable.
But what if you don't want to distribute that funky ReportViewer.exe? Maybe you just want to throw the files on a PC and let a prototype tester have at it?
Sure, you can do that - first snag these two files from C:\Program Files\Microsoft Visual Studio 8\ReportViewer
Microsoft.ReportViewer.Common.dll Microsoft.ReportViewer.WinForms.dll
And now the tricky part, you need to snag Microsoft.ReportViewer.ProcessingObjectModel.dll from the GAC. It will be located in a directory something like C:\WINDOWS\assembly\GAC_MSIL\Microsoft.ReportViewer.ProcessingObjectModel\8.0.0. 0__b03f5f7f11d50a3a
...but remember, you'll need to use the Command Line to get at this file, because of the cool Explorer add-in for the GAC.
Put the three ReportViewer assemblies in your app's BIN folder and you should be good to go!
|
 |
|
Comments (8)
|
|
|
|
Groovy, Shadowy Tooltips |
|
Andy's Blog
|
By Andy Beaulieu on
5/18/2006 12:30 AM
|
|
|
|
With all the neat-o AJAX and Atlas sites showing up, one of the recurring things I've noticed is groovy, shadowy tooltips. What am I talking about? If you haven't tried Netflix yet, at least visit their site and try hovering over a movie image. You'll see a nice popup flash up with title details. I really like the shadows that show up around this popup, it really adds a professional touch.
So how is this done? Well, it should be possible to use PNG images to define an alpha channel that supports transparency. Most browsers except Internet Explorer support this. But in order to support the most browsers, you have to use a klugey method that uses an AlphaImageLoader Filter in IE. I'll show some code that implements this kluge, but first let's look at how we can create a PNG file that has this nice alpha channel...
I'll be using Paint.NET because it's free and it does a fine job of managing layers and transparency for PNG's!
(1) Create a new image by selecting File/New. Be sure to input your desired height and width.
(2) Set the image background to transparent by selecting Layers/Layer Properties and setting the Opacity to 0.
(3) In this step we will create the shadow layer Select Layers/Add New Layer. Select the “Draw filled shape with outline” option button on the toolbar.

(4) Set both the foreground and background colors to a dark gray

(5) Draw out a rectangle (or other shape) for the background shadow.

(6) Next, blur the shadow by selecting Effects/Blurs/Gaussian. Note how the “shadow” gets blurred out!
(7) Next, we add the “real object” that is casting the shadow. Overlay another rectangle or other object that is casting the shadow.
That's it! We now have a nice PNG file that can implement alpha transparency. But in order to get this to work cross-browser, we need to do a couple of dirty, kludgey things.
First, we need to have a "bogus proxy image" that is at least 1x1 pixel and completely transparent. You can create a 1x1 GIF image that is completely transparent, that will work fine. Let's call that image bogusPixel.gif.
Next, we need some javascript that will figure out if we are in IE and need to apply an AlphaImageLoader filter. This is because IE doesn't really support alpha channel PNG's, but has a filter that does support them.
<script language="javascript"> var bInitialized; function showImg(id) { var img = document.getElementById(id); img.style.visibility='visible'; if (navigator.appVersion.indexOf("MSIE")>-1) { if (!bInitialized) { bInitialized = true; img.style.width = img.width; img.style.height = img.height; img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod='scale', src='" + img.src + "')"; img.src = "images/bogusPixel.gif"; } } }
function hideImg(id) { document.getElementById(id).style.visibility='hidden'; }
< FONT>< FONT>script>
And FINALLY we can implement our little tooltip!
<img id="imgBalloonTip" src="images/Balloon.png" style="visibility:hidden">
<div style="width:50px; border:solid 2px Black;" onmouseover="showImg('imgBalloonTip');" onmouseout="hideImg('imgBalloonTip');"> Try Me < FONT>div>
And that's about it. So to give this a try, hover over the "Try This" div below and you'll see a groovy shadowy popup:
Try Me
|
 |
|
Comments (0)
|
|
|
|
|
 |
|
 |
|
|