Monday, December 3, 2007

Free ASP.NET Rich Text Editor control

Check out this awesome free rich text editor. The source code can be found at CodePlex at: RTE (Rich Text Editor) ASP.NET Control

The project page lists the following features 

Supported Browsers: Internet Explorer and FireFox
Supported Styles / Formats: Bold, Italic, Underline, Justify, indentations, Plain Lists, Numbered Lists
Supported Commands: Copy, Paste, Cut, Add Hyperlink, Set Foreground Color, Set Highlight Color, Set Fonts, Set Font Sizes, Insert Smiles
Supported Views: Text View, Html View

You can see a demo on this page: http://rteditor.members.winisp.net/

Technorati Tags:

Visual C# 2008 shortcuts

I found a nice PDF file that lists the most frequently used shortcuts in Visual C# 2008. You can download it from the Visual C# 2008 Keybinding Reference Poster page. I haven't had the time to check how many shortcuts differ from those in Visual C# 2005.

If you are using Visual C# 2005 check out this post: Visual C# 2005 shortcuts

Technorati Tags: , , ,

Friday, September 28, 2007

Partial methods

Visual Studio 2008 allows the use of partial methods. Partial methods are nothing but a compiler trick (just like partial classes). Designer generated code can provide hooks into their class methods, by using the partial keyword. Users of the class can then hook into those methods and provide their own implementation. When a partial method has no body then the partial method is not emitted to metadata. So in a sense they are optional methods.

Check out this video on partial methods titled: Partial Methods in C#3 and VB9 by Daniel Moth. In it he explains what partial methods are and their limitations. He also compares them to the Conditional attribute and event handlers.

Technorati Tags: ,

Friday, September 7, 2007

External settings file for ClientSettingsSection (applicationSettings)

Very often we define application settings in application configuration sections and would like to isolate the configuration section into an external settings file. Creating external settings file using the configSource attribute for the predefined configuration sections (AppSettings, ConnectionStrings etc) is well documented. But the literature for custom configuration section is sparse.

Listed below is a sample configuration file that contains a configSource attribute being used in a ClientSettingsSection. I have kept only the essential parts of the file:

   1: <configSections>
   2:   <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup">
   3:     <section name="MyApplication.Properties.Settings" type="System.Configuration.ClientSettingsSection"/>
   4:   </sectionGroup>
   5: </configSections>
   6:  
   7: <applicationSettings>
   8:   <MyApplication.Properties.Settings configSource="BusinessLogic.config" />
   9: </applicationSettings>

Line 8: Using the configSource attributed to define an external settings file called "BusinessLogic.config"


A couple of things of note:
- Unlike how it does for predefined configuration sections, Visual Studio does not provide intellisense when trying to add the configSource attribute to ClientSettingsSection.
- The external settings file has to be in the same directory or subdirectory as the configuration file. So line 8 can be replaced with the following line:


<MyApplication.Properties.Settings configSource="ConfigFiles\BusinessLogic.config" />

Listed below is the "BusinessLogic.config" file


   1: <MyApplication.Properties.Settings>
   2:   <setting name="InitializationVector" serializeAs="String">
   3:     <value>1234567890abc!@#</value>
   4:   </setting>
   5:   <setting name="KeySize" serializeAs="String">
   6:     <value>256</value> 
   7:   </setting>
   8: </MyApplication.Properties.Settings>

 

Technorati Tags: , ,

Thursday, September 6, 2007

Getting line numbers in exception stack trace in a Windows Service

The Exception.ToString() method contains call stack information when the exception was thrown. However if the PDB files from the assemblies involved are available, this information also contains file names and line numbers at each level of the stack trace. Needless to say that this information can be very beneficial to the developer.

The CLR will look for the PDB files in the runtime working directory, which for most applications is the installation directory itself. However for windows services the working directory is the windows systems32 directory (For eg: C:\Windows\System32). So exceptions thrown in assemblies that are hosted in a windows service, the call stack rarely contains the file names and line numbers even when the right PDB files are available.

The working directory of a windows service can be changed using the following line:

   1: Environment.CurrentDirectory = System.AppDomain.CurrentDomain.BaseDirectory;

Once the working directory has been changed to the base directory, the CLR should pick up the right PDB files and the stack trace should contain line numbers.


Technorati Tags: , , ,

Friday, August 31, 2007

Shortcut: Launch Visual Studio Command Prompt from Visual Studio

In Visual Studio 2005:

  1. Go to Tools > External tools
  2. Click Add and enter the following information
    1. Title: Cm&d
    2. Command:  %comspec%
    3. Arguments: /k ""C:\Program Files\Microsoft Visual Studio 8\VC\vcvarsall.bat"" x86
    4. Initial Directory: $(ItemDir)
  3. Click Apply / OK 

In Visual Studio 2008:

  1. Go to Tools > External tools
  2. Click Add and enter the following information
    1. Title: Cmd
    2. Command:  %comspec%
    3. Arguments: /k ""C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"" x86
    4. Initial Directory: $(ItemDir)
  3. Click Apply / OK

Technorati tags: ,

Wednesday, August 29, 2007

Visual C# 2005 shortcuts

I found a nice PDF file that lists the most frequently used shortcuts in Visual C# 2005. You can download it from the Visual C# 2005 Keyboard Shortcut Reference Poster page.

Technorati Tags: ,

Friday, July 27, 2007

Visual Studio 2008 Beta 2 released.

Find it using this link: Visual Studio 2008 Beta 2.

Rob Caron has an easier way to download Visual Studio 2008 Beta 2.

Looking for an easier way to download those huge Visual Studio 2008 Beta 2 files? Go grab the Microsoft Secure Content Downloader from Microsoft Research.

Unfortunately it not install over Beta 1, Beta 1 has to be uninstalled. But it does have a go-live license, which means it can be used in production It also means it very close to being feature complete. I just can't wait for it to be released.

Make sure you read the Installation notes section of Scott Guthrie's blog post. Also Daniel Moth blogs his Visual Studio 2008 installation experience.

Thursday, July 26, 2007

Nested GridViews and Hiding

Often we use nested GridView controls, so that individual rows in the master GridView can display a nested GridView in one of its columns. This is especially useful to show master/details relationships. However sometimes we might want to show the nested GridView only for the selected row. This post discusses one way to do it.

Prerequisites

Understanding of the GridView control.
Understanding of TemplateField class.
Understanding of SqlDataSource class.

If you are looking to understand how to create nested GridView controls, there is an excellent article on MSDN titled: Walkthrough: Creating a Nested GridView Control

Listed below is the source code for my aspx page. I've kept only the essential parts of the code:


   1: <asp:SqlDataSource ID="masterDataSource" .../>
   2: <asp:SqlDataSource ID="nestedDataSource" ... />
   3: <asp:GridView ID="masterGrid" OnSelectedIndexChanged="masterGrid_SelectedIndexChanged" ...>
   4:     <Columns>
   5:         <asp:BoundField ... />
   6:         <asp:BoundField ... />
   7:         <asp:TemplateField>
   8:             <ItemTemplate>
   9:                 <asp:GridView ID="nestedGrid" DataSourceID="nestedDataSource" Visible="false">
  10:                     <Columns>
  11:                         <asp:BoundField ... />
  12:                     </Columns>                        
  13:                 </asp:GridView>
  14:             </ItemTemplate>
  15:         </asp:TemplateField>
  16:     </Columns>
  17: </asp:GridView>


Line 1: SqlDataSource called masterDataSource which will be used to populate the master GridView (masterGrid, line 3)
Line 2: SqlDataSource called nestedDataSource which will be used to populate the nested GridView (nestedGrid, line 9)
Line 3: Master GridView called masterGrid. Uses masterDataSource as the data source. Specifies masterGrid_SelectedIndexChanged as the method handler for SelectedIndexChanged event.
Line 9: Nested GridView called nestedGrid. Uses masterDataSource as the data source. Insert as a TemplateField.

Listed below is the source code for the masterGrid_SelectedIndexChanged event:

   1: protected void masterGrid_SelectedIndexChanged(object sender, EventArgs e)
   2: {
   3:     foreach (GridViewRow row in masterGrid.Rows)
   4:     {
   5:         row.FindControl("nestedGrid").Visible = false;
   6:     }
   7:     //Retrieve the data to be filled in the nestedGrid for the selected row
   8:     nestedDataSource.SelectParameters[0].DefaultValue = masterGrid.SelectedDataKey[0].ToString();
   9:     nestedDataSource.DataBind();            
  10:     //Set the visibility of for the nestedGrid for the selected row
  11:     masterGrid.SelectedRow.FindControl("nestedGrid").Visible = true;            
  12: }

Line 3-6: I hide all the nestedGrid controls.
Line 11: For only the selected row I show the nestedGrid. It was as simple as that!.




Tuesday, July 17, 2007

Multi-targeting FAQ

What is multi-targeting?

Starting with Visual Studio 2008 developers will be able to target multiple versions of the .NET Framework using the same version of Visual studio. Developers will be able to start taking advantage of the new features Visual Studio provides without having to always upgrade their existing projects and deployed applications to use a new version of the .NET Framework library.

Isn't this currently possible to target v1.1 using Visual Studio 2005?

Currently, applications can be built to target the 1.1 Framework with Visual Studio 2005 using MSBee; however, the setup and compilation can be tricky at best. In Visual Studio 2008, Microsoft looks to bring the process of targeting version 2.0 and above of the .NET Framework directly into the IDE

What kind of support does Visual Studio 2008 provide?

  • Creating new projects: Automatically filter and show only those project templates that are available for the currently selected version when creating a new project.
  • Adding references: The assembly reference picker dialog will automatically gray out assemblies that are not available for the currently selected version.
  • Config files: The IDE will use the schema of the currently selected version for the configuration files.
  • Controls: Only those controls that are available for the currently selected version will be shown in the toolbox.
  • Compiler settings: Compiler settings are automatically set as per the currently selected version.

Can an existing project be upgraded?

Yes. The targeted version can be changed from the project's properties page. Once the Target Framework is changed, Visual Studio will update the project with the new assemblies, controls, and compiler settings.

Are all versions supported?

Unfortunately the VS 2008 multi-targeting support only works with .NET 2.0, .NET 3.0 and .NET 3.5 - and not against older versions of the framework.  The reason for this is that there were significant CLR engine changes between .NET 1.x and 2.x that make debugging very difficult to support.  In the end the costing of the work to support that was so large and impacted so many parts of Visual Studio that we weren't able to add 1.1 support in this release.

What about future versions of Visual Studio and .NET framework? Will multi-targeting be supported?

Yes. Future versions will follow the same model.

What about older projects that are opened in Visual Studio 2008?

The user will be presented with an option to run a conversion utility which will allow the user to upgrade to a newer version. (Pretty similar to what happens in Visual Studio 2005)

Can I use Visual Studio 2008 and Visual Studio 2005 interchangeably for a .NET 2.0 project?

Visual Studio 2008 makes changes to the solution file that prevents the project from being loaded in Visual Studio 2005. Other than the changed to the solution file, no changes are made to any other files.

Will multi-targeting work with ASP.NET and AJAX?

Applications built using ASP.NET AJAX 1.0 running on ASP.NET 2.0 will work inside VS 2008 (you'd just target the .NET 2.0 runtime).  You can also then easily upgrade it to .NET 3.5.

Will ASP.NET 2.0 projects developed in Visual Studio 2008? run within existing ASP.NET 2.0 app pools ?

Yes.

What versions of Visual Studio 2008 will support multi-targeting?

Multi-targeting will be supported with both Visual Studio as well as Visual Web Developer Express and the other Express products.

Technorati Tags:

Monday, July 16, 2007

Visual Studio 2008 to be released in 2007

Are per the blog posts found here and here, Visual Studio 2008 will ship before the end of this year. Also it will be launched along with Windows Server 2008 and Microsoft SQL Server 2008 at an event here in Los Angeles on 27 February 2008.

As per Scott Guthrie

We typically release products several weeks/months before we "launch" them. You'll be able to buy the final release of VS 2008 and start using it before we hold the launch event.

Wednesday, July 11, 2007

Web service time out in Visual Studio 2005 debug mode

We use a web service to standardize US addresses (convert Av to Ave., LA to Los Angeles etc). The web service has been around since a long time and is used by a lot of applications written in .NET 1.1. But today when using it in Visual Studio 2005 I noticed something. It threw a WebException.Timeout  exception every time I invoked it while I was debugging. It worked fine when invoked while the application was running normally, just not while being debugged. That's when a colleague asked me to add the following lines to my machine.config file, after which every worked fine.

<system.diagnostics>
<switches>
<add name="Remote.Disable" value="1"/>
</switches>
</system.diagnostics>



Symptoms: A web service method runs fine when invoked normally, but throws a exception when it is invoked from Visual Studio 2005 in debug mode. The web service method runs fine when invoked from Visual Studio 2003 in debug mode.


Cause:  It seems that the Visual Studio 2005 debugger some data to each outgoing request which is used for debugging. However, this data destroys the well-formedness of the request.

Tuesday, July 3, 2007

Expresso - The best regular expression tool

One of the projects I am working on involves screen scraping information off various web sites. Shortly after I started, I quickly learnt that any attempts towards serious screen scraping will required the use of regular expressions to detect patterns in the HTML source. And so began my (short lived) search for a tool to help me build and test regular expressions - thanks to Expresso 3.0 by Ultrapico.

Expresso is by far the best free regular expression tool I have used to date. It has the following features that I consider very important in a regular expression tool (and much, much more)

  1. Expression builder (Expresso enables you to create regular expressions without having to remember an arcane syntax.)
  2. Expression library (library of common and frequently used expressions) and the ability add to it.
  3. Expression analyzer (Complex regular expressions can be notoriously obtuse to read)
  4. Expression validator
  5. Grouping of matches showing captured groups.

 But the wow factor really kicked in when I saw that Expresso has many more features like exporting results, partial matching, performance testing, character class subtraction etc.

Subscribe to my feed in your favorite feed reader