The blog has moved to a new address. The blog is now located at http://devintelligence.com

Friday, August 11, 2006

Is there any way to change or customize the path of the user.config file?


The LocalFileSettingsProvider does not provide a way to change the files in which settings are stored.


Note: The provider itself doesn't determine the config file locations in the first place - it is the configuration system.


If you need to store the settings in a different location for some reason, the recommended way is to write your own SettingsProvider. This is fairly simple to implement and you can find samples in the .NET 2.0 SDK that show how to do this. Keep in mind however that you may run into the same isolation issues mentioned above.




Technorati : , ,

How can I get the user.config file path programmatically in a non-Clickonce app?


If you want to get to the path programmatically, you can do it using the Configuration Management API. For example, here is how you can get the local user.config file path:


Note: You need to add a reference to System.Configuration.dll


Configuration config =
ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.PerUserRoamingAndLocal);
Console.WriteLine("Local user config path: {0}", config.FilePath);




Technorati : , ,

Why is there a version number in the user.config path?


There are a couple of reasons why the user.config path is version sensitive:



  • To support side-by-side deployment of different versions of an application (you can do this with Clickonce, for example). It is possible for different versions of the application to have different settings saved out.

  • When you upgrade an application, the settings class may have been altered and may not be compatible with what's saved out, which can lead to problems.




Technorati : , ,

Why is the user.config path so obscure?


The path construction algorithm has to meet certain rigorous requirements in terms of security, isolation and robustness. While we tried to make the path as easily discoverable as possible by making use of friendly, application supplied strings, it is not possible to keep the path totally simple without running into issues like collisions with other apps, spoofing etc.




Technorati : , ,

Where is the user.config file located in a non-Clickonce app?


The path of the user.config files is structured as follows:
<Profile Directory>\<Company Name>\<App Name>_<Evidence Type>_<Evidence Hash>\<Version>\user.config


Where:



  • <Profile Directory> - is either the roaming profile directory or the local one. Settings are stored by default in the local user.config file. To store a setting in the roaming user.config file, you need to mark the setting with the SettingsManageabilityAttribute with SettingsManageability set to Roaming.

  • <Company Name> - is typically the string specified by the AssemblyCompanyAttribute (with the caveat that the string is escaped and truncated as necessary, and if not specified on the assembly, we have a fallback procedure).

  • <App Name> - is typically the string specified by the AssemblyProductAttribute (same caveats as for company name).

  • <Evidence Type> and <Evidence Hash> - information derived from the app domain evidence to provide proper app domain and assembly isolation.

  • <Version> - typically the version specified in the AssemblyVersionAttribute. This is required to isolate different versions of the app deployed side by side.


Note: The file name is always simply 'user.config'




Technorati : , ,

Why can't I change application scoped settings at runtime?


Application scoped settings are essentially read only from the application's point of view, and aren't meant to be changed by users, but rather only the administrator. An additional reason for this has to do with how the default SettingsProvider stores settings. Application scoped settings are stored in the exe configuration file, and user scoped settings are stored in user.config files located in the user data path. Generally, exe config files should not be written to at runtime by the application, since the user may not have access to them. In addition, it is normally not a good idea for a user to change a file that affects every other user of the application.




Technorati : , , ,

What is the difference between application scoped and user scoped settings?


There are generally two main types of settings that applications want to store:



  1. Static data like connection strings and web references that don't change often, but should still be possible for an admin to change.

  2. User preferences and customization settings that can change at any time.


Application scoped settings are useful in scenario (1) and user scoped settings are useful in scenario (2).

Wednesday, July 19, 2006

How do I use the WebBrowser as a HTML editor?


You can access, and write to, the HTML behind a web page being displayed by the WebBrowser using the WebBrowser.DocumentText property.




Technorati : ,

Why does my application with multiple WebBrowser controls use so much memory?


The WebBrowser control is a resource-intensive control. Be sure to call the Dispose method when you are finished using the control to ensure that all resources are released in a timely fashion. You must call the Dispose method on the same thread that attached the events, which should always be the message or user-interface (UI) thread.




Technorati : , , ,

Where can I find information on the native interfaces?


The WebBrowser control is primarily a managed wrapper of the WebBrowser ActiveX object. There are four main unmanaged interfaces that are wrapped in one form or another:



  1. IWebBrowser2 - The core WebBrowser interface.

  2. DWebBrowserEvents2 - The WebBrowser events.

  3. IDocHostUIHandler - Provides advanced functionality such as: custom context menus, disabling accelerators & providing custom objects to the html script. The WebBrowser control QI's it's Site to obtain this interface.

  4. IinternetSecurityManager - Provides custom security for the browser control.




Technorati : , , ,

Tuesday, June 27, 2006

mentas Ribbon

Basic and easy .NET 2.0 control to make your application feel like MS Office 2007 UI experience.

Download mentas Ribbon

Technorati : , , , ,
Ice Rocket : , , , ,

A free charting library for .NET

ZedGraph is a set of classes, written in C#, for creating 2D line and bar graphs of arbitrary datasets. The classes provide a high degree of flexibility - almost every aspect of the graph can be user-modified. At the same time, usage of the classes is kept simple by providing default values for all of the graph attributes. The classes include code for choosing appropriate scale ranges and step sizes based on the range of data values being plotted.

ZedGraph also includes a UserControl interface, allowing drag and drop editing within the Visual Studio forms editor, plus access from other languages such as C++ and VB.

Example charts generated with ZedGraph
filled_curve_150.gif vertical_bars_labels_150.gif

pie_demo_150.gif combo_150.gif

modified_initial_150.gif

Technorati : , , ,
Ice Rocket : , , ,

TopMost Form


"A topmost form is a form that overlaps all the other (non-topmost) forms even if
it is not the active or foreground form. Topmost forms are always displayed at
the highest point in the z-order of the windows on the desktop. You can use this
property to create a form that is always displayed in your application,
such as a Find and Replace tool window."


The well known issue that the TopMost Form stealing focus ...
The fallowing code can solve the problem.


private const int SW_SHOWNA = 8;
private const int SW_SHOWNA = 8;
[DllImport("user32", CharSet = CharSet.Auto)]
private extern static int ShowWindow( IntPtr hWindow, int nCmd );


public void MakeTopMostForm(Form frm)
{
ShowWindow(frm.Handle, SW_SHOWNA);
}




Sunday, June 25, 2006

BytesRoad.NetSuit Library 2.0

BytesRoad.NetSuit Library 2.0 is a free network library for .NET platform distributed under GNU General Public License. The library is written in C# language and source codes are also available.

FTP functionality is exposed by FtpClient class . This class contains high level methods that allow you to communicate with FTP server. Also available SocketEx class. This class may be used instead of the .NET Framework's Socket class wish your application to be able to communicate through the proxies (Socks4, Socks5 etc).

FTP Implementation features


  • Fully compliant with RFC 959 (File Transfer Protocol) and related documents
  • Comprehensive reference for the component (as compiled HTML file) integrated with .NET Framework SDK v1.1 help
  • Support communication with FTP server through the proxies. Following proxies are currently supported:
    • Socks4
    • Socks4a
    • Socks5, username/password authentication method supported
    • Web proxy (HTTP CONNECT method), basic authentication method supported
  • All methods requiring networking hava synchronous and asynchronous versions
  • Implementation of asynchronous methods follows .NET Asynchronous methods pattern
  • Each operation may be configured with required time out period
  • "Store unique file" command can be customized by specifying regular expression
  • Directory listing parser supports common directory listing formats and can be customized by the user-defined parser
  • Exception oriented error handling
  • Provide events for monitoring the communication process:
    • Event during data transferring
    • Event during receiving ftp items
    • Event on each FTP command sent
    • Event on each FTP response received
  • Supported on .NET Framework v1.0 and later


Sockets implementation features


  • Comprehensive reference for the component (as compiled HTML file) integrated with .NET Framework SDK v1.1 help
  • Following proxies are currently supported:
    • Socks4
    • Socks4a
    • Socks5, username/password authentication method supported
    • Web proxy (HTTP CONNECT method), basic authentication method supported
  • All methods requiring networking have synchronous and asynchronous versions
  • Implementation of asynchronous methods follows .NET Asynchronous methods pattern
  • Each operation may be configured with required time out period
  • Exception oriented error handling
  • Supported on .NET Framework v1.0 and later

Download BytesRoad.NetSuit Library 2.0

Technorati : , ,
Ice Rocket : , ,

Wednesday, June 21, 2006

Free SharePoint 2007 Book

"Future or current SharePoint developers should at least flip through the book to build a picture of how MOSS 2007 fits together and what the concepts are -- changes to the security model, site definitions, site features, Content Types, how Workflow is integrated, Excel Services -- there are a hundred small topics, you owe it to yourself to get a handle on the big picture."

Table of Contents

  • Microsoft Windows SharePoint Services 3.0
  • Building Solutions with Office SharePoint Server 2007
  • Building a Basic SharePoint Site
  • Organizing List and Documents with Site Columns and Content Types
  • Working with Features in Windows SharePoint Services
  • Windows SharePoint Services Core Development
  • Creating Workflows: The Missing Piece of Office Productivity
  • Introducing Excel Services
  • Microsoft Office InfoPath 2007 and Microsoft Office Forms Server 2007

Download

[Via Roy Osherove's Blog]

Technorati : , , ,
Ice Rocket : , , ,

Wednesday, June 14, 2006

Creating clonable menu items in .Net 2.0 ( Implementing CloneMenu method )

In Windows Forms FAQ( .Net 2.0) I found that the CloneMenu method is not implemented ...:-(

"With the entire ToolStrip family of controls we do not have an integrated commanding
architecture nor do we support cloning of items to appear in multiple places.
We do support reusing the same ToolStripDropDown or ContextMenuStrip in multiple places (non-nested).
We understand this may require more state management and maintenance code and are looking
at ways to improve this in the future.
Erick Ellis, 6 January 2005 # (MS)"


Here's "fast and dirty" solution:

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication66
{
class CloneToolStripLabel:ToolStripLabel
{
public CloneToolStripLabel( string text )
: base(text)
{
}
public CloneToolStripLabel CloneMenu()
{
return ( CloneToolStripLabel )this.MemberwiseClone();
}
}
}


Usage:

CloneToolStripLabel menuItem = new CloneToolStripLabel("Kuku");
toolStrip1.Items.Add(menuItem);
toolStrip2.Items.Add(menuItem.CloneMenu());

Also you can read this post

Technorati : , , ,
Ice Rocket : , , ,

Sunday, June 11, 2006

Save and restore the size,location and state of a Windows Form in .NET 2.0

The fallowing example saves the properties (location, size and windows state) of a form to app.config
when the form is closed and restores the form state when it is loaded.

Create three properties called Size ,Location and WindowState in project settings dialog as shown in picture:

Modify Form.Load and FormClosing methods (Use DesktopBounds (instead Form.Location and Size)
to place form correctly on a multi screen desktop )
 

private void Form1_Load( object sender, EventArgs e )

{

// restore location and size of the form on the desktop

this.DesktopBounds =

new Rectangle(Properties.Settings.Default.Location,

Properties.Settings.Default.Size);

// restore form's window state

this.WindowState = ( FormWindowState )Enum.Parse(

typeof(FormWindowState),

Properties.Settings.Default.WindowState);

}


private void Form1_FormClosing( object sender, FormClosingEventArgs e )

{


Properties.Settings.Default.Location = this.DesktopBounds.Location;

Properties.Settings.Default.Size = this.DesktopBounds.Size;

Properties.Settings.Default.WindowState =

Enum.GetName(typeof(FormWindowState), this.WindowState);

// persist location ,size and window state of the form on the desktop

Properties.Settings.Default.Save();

}

 
 

Technorati : , , ,

Saturday, June 10, 2006

PowerShell Editor and IDE.

PowerShellIDE is the PowerShell Editor and IDE.

It is a graphical user interface that helps explore and exploit the vast power available with PowerShell. It contains a debugger, lets you step through PowerShell scripts, explore variables as you run your scripts and also supports many Intellisense-like functions.

Download PowerShellIDE

Technorati : , , ,
Ice Rocket : , , ,

MSBuild Sidekick

MSBuild Sidekick is a GUI application for creating and editing build project files for Microsoft Build engine. The application provides full-fledged graphic user interface as alternative to editing build project files by hand. The full range of MSBuild schema elements is supported.


MSBuild Sidekick features:

  • Load and modify any file complying to MSBuild schema
  • View build project structure in a tree view that displays tasks used in build, property groups and properties, item groups and items, targets and targets tasks and imported build projects.
  • Show or hide presentation of imported definitions in a project tree view
  • View MSBuild project raw XML source as you modify the project
  • Modify project default targets
  • Add or remove tasks used in build project from external assembly
  • Add, remove or modify property groups
  • Add, remove or modify properties in property groups
  • Add, remove or modify item groups
  • Add, remove or modify items in item groups
  • Add, remove or modify targets
  • Add, remove or modify selected target's tasks, tasks order
  • Modify selected task properties (including output properties specification)
  • Import or remove external build projects
  • Open any imported project from the loaded project

Download MSBuild Sidekick

[Via Larkware News]

Technorati : , , ,
Ice Rocket : , , ,

Thursday, June 01, 2006

How to prevent the UserControl class to appear in the Visual Studio toolbox

You can prevent the UserControl class to appear in the Visual Studio toolbox by adding fallowing attribute to it

[System.ComponentModel.ToolboxItem(false)]

Remember that this attribute is inheritable ,so derived UserControls must place have a System.ComponentModel.ToolboxItem(false) attribute if they want to be available on the Visual Studio toolbox .

Technorati : , , , ,
Ice Rocket : , , , ,