Wednesday, August 31, 2011

How to Reset Visual Studio 2010 Settings to change default language environment e.g. C# to VB

You can reset the integrated development environment (IDE) to a previous state using the Import and Export Settings
wizard. All settings and categories are applied by default; if you want to specify which settings to change, use the option
Import selected environment settings.

To reset your settings

1.      On the Tools menu, click Import and Export Settings.
2.      On the Welcome to the Import and Export Settings Wizard page, clicks Reset all settings and then click on Next
3.      If you want to save your current settings combination, click Yes, save my current settings, specify a file name, and
then click on Next Button.
If you want to delete your current settings combination, choose No, just reset settings, overwriting my current settings,
and then click Next Button. This option does not delete default settings, which will still be available the next time you
use the wizard.
4.      In Which collection of settings do you want to reset to, select a settings collection from the list.
5.      Click Finish.
The Reset Complete page alerts you to any problems encountered during the reset.
When you run the Visual Studio then it will ask you to choose the default language environment. Now you can choose
your working language environment.

Tuesday, August 30, 2011

ASPxFileManager - How to Create Custom Thumbnails Icons for Files

To show your custom thumbnail icons in the ASPxFileManager Control, just use its CustomThumbnail
Event to specify your custom image file.

There you will get the file extension using the e.File.Extension property to set your image
using the  e.ThumbnailImage.Url property according to your file type.
public void fileManager1_CustomThumbnail(object sender, FileManagerThumbnailCreateEventArgs e)
            switch (e.File.Extension)
                case ".avi":
                    e.ThumbnailImage.Url = "Images/movie.png";
                case ".txt":
                    e.ThumbnailImage.Url = "Images/txt.png";
                case ".mp3":
                    e.ThumbnailImage.Url = "Images/music.png";
                case ".xml":
                    e.ThumbnailImage.Url = "Images/code.png";

Thursday, August 25, 2011

Set Custom Error Message in ASPxGridView

This enable you to specify whether row data is valid and whether the row can be updated.
The RowValidating event is automatically raised when a row is about to be updated, and allows you to
specify whether its data is valid. To manually validate the edited row, call the
DoRowValidation method.

To obtain the edited row's values, use the event parameter's ASPxDataValidationEventArgs.NewValues
property. The old values are returned by the
ASPxDataValidationEventArgs.OldValues property. If the
value is invalid, use the
ASPxDataValidationEventArgs.Errors property to specify the error description
text. As a result, an error icon will be displayed next to the invalid value. Pointing to the icon shows the
hint with the error description.

using DevExpress.Web.ASPxGridView;
using System.Collections.Generic;
namespace Petshop.Core
    class RowValidationDemo
        protected void grid_RowValidating(object sender,
DevExpress.Web.Data.ASPxDataValidationEventArgs e)
            // Checks for null values.
            foreach (GridViewColumn column in grid.Columns)
                GridViewDataColumn dataColumn = column as GridViewDataColumn;
                if (dataColumn == null) continue;
                if (e.NewValues[dataColumn.FieldName] == null)
                    e.Errors[dataColumn] = "Value cannot be null.";
            // Displays the error row if there is at least one error.
            if (e.Errors.Count > 0) e.RowError = "Please, fill all fields.";

            if (e.NewValues["ContactName"] != null &&
                e.NewValues["ContactName"].ToString().Length < 2)
                AddError(e.Errors, grid.Columns["ContactName"],
                "Contact Name must be at least two characters long.");
            if (e.NewValues["CompanyName"] != null &&
            e.NewValues["CompanyName"].ToString().Length < 2)
                AddError(e.Errors, grid.Columns["CompanyName"],
                "Company Name must be at least two characters long.");
            if (string.IsNullOrEmpty(e.RowError) && e.Errors.Count > 0)
                e.RowError = "Please, correct all errors.";

        void AddError(Dictionary<GridViewColumn, string> errors,
        GridViewColumn column, string errorText)
            if (errors.ContainsKey(column)) return;
            errors[column] = errorText;

        protected void grid_HtmlRowPrepared(object sender,
        ASPxGridViewTableRowEventArgs e)
            // Checks whether the generated row has the errors.
            bool hasError = e.GetValue("ContactName").ToString().Length <= 1;
            hasError = hasError || e.GetValue("CompanyName").ToString().Length <= 1;
            hasError = hasError || e.GetValue("Country") == null;
            // If the row has the error(s), its text color is set to red.
            if (hasError)
                e.Row.ForeColor = System.Drawing.Color.Red;

        protected void grid_StartRowEditing(object sender,
        DevExpress.Web.Data.ASPxStartRowEditingEventArgs e)
            // Validates the edited row if it isn't a new row,.
            if (!grid.IsNewRowEditing)

The HtmlRowPrepared event is handled to paint the row's contents red if the row is invalid. This event is raised
for each data row when the corresponding row within the table has been created. This indicates rows within
invalid data.

The StartRowEditing event is handled to display erorrs (if any) within the edited row when an end-user
switches to edit mode.

Another Way is collect the exception at ASPxGridView CustomErrorText event and set the e.ErrorText property to show
the custom error text.
string customeErrorMessage = string.Empty;

(e.Exception is ExceptionType)
       customeErrorMessage = your message;
e.ErrorText = customeErrorMessage;

When the ASPxGridView launches a callback that catches exceptions by default, since each exception during page processing cancels the generation of the page. Even if a callback, the ASPxGridView (and other controls DX) catch exceptions to display in the proper format. For example, the ASPxGridView displays an error, display an alert ASPxCallbackPanel and so on.
If you catch exceptions with a try ... catch the ASPxGridView see that all is well and not make the error message.



Wednesday, August 24, 2011

Specified method is not supported - ASPxGridView Exception

When you use a complex LINQ query, the result that is returned from the Linq-To-Sql is a
projection that can't be edited. All its properties are set as read-only.
The DataController determines that the datasource has fields with get accessors only, and
"tells" the ASPxGridView to render fields in readonly mode.

A possible solution is to remove the ReadOnly attribute in the ASPxGridView.CellEditorInitialize
event handler:
e.Editor.ReadOnly = false;
A custom updating and inserting can be implemented by handling the ASPxGridView.RowUpdating
and ASPxGridView.RowInserting events.
var obj = /* find an object by e.Keys[0] */;
obj.Prop = e.NewValues["Prop"];

e.Cancel = true;

When you do insert or Update Operations in the DevExpress ASPxGridView then this kind of
exception occurred after completing these operations. To prevent this just add the following two lines
of code to avoid the problem in the  RowInsert or RowUpdating events.
e.Cancel = true;

Tuesday, August 23, 2011

Insert, edit and delete data in a data table by ASPxGridView at runtime

It shows how to insert, edit and delete data in a data table by ASPxGridView. The data table and the
grid are created at runtime.
public partial class _Default : System.Web.UI.Page {
    private DataTable dataTable;

    protected void Page_Load(object sender, EventArgs e) {

    private DataTable CustomDataSourse {
        get {
            if (dataTable != null)
                return dataTable;

            dataTable = ViewState["CustomTable"] as DataTable;
            if (dataTable != null)
                return dataTable;

            dataTable = new DataTable("CustomDTable");
            dataTable.Columns.Add("Id", typeof(Int32));
            dataTable.PrimaryKey = new DataColumn[] { dataTable.Columns[0] };
            dataTable.Columns.Add("Data", typeof(string));

            dataTable.Rows.Add(0, "Data1");
            dataTable.Rows.Add(1, "Data2");
            dataTable.Rows.Add(2, "Data3");
            dataTable.Rows.Add(3, "Data4");
            dataTable.Rows.Add(4, "Data5");
            ViewState["CustomTable"] = dataTable;

            return dataTable;
    protected void grid_DataBinding(object sender, EventArgs e) {
        (sender as ASPxGridView).DataSource = CustomDataSourse;
    protected void grid_DataBound(object sender, EventArgs e) {
        ASPxGridView g = sender as ASPxGridView;
        for (int i = 0; i < g.Columns.Count; i++) {
            GridViewDataTextColumn c = g.Columns[i] as GridViewDataTextColumn;
            if (c == null)

            c.PropertiesTextEdit.ValidationSettings.RequiredField.IsRequired = true;


    protected void grid_RowDeleting(object sender, ASPxDataDeletingEventArgs e) {
        int id = (int)e.Keys[0];
        DataRow dr = CustomDataSourse.Rows.Find(id);

        ASPxGridView g = sender as ASPxGridView;
        e.Cancel = true;
    protected void grid_RowUpdating(object sender, ASPxDataUpdatingEventArgs e) {
        int id = (int)e.OldValues["Id"];
        DataRow dr = CustomDataSourse.Rows.Find(id);
        dr[0] = e.NewValues["Id"];
        dr[1] = e.NewValues["Data"];

        ASPxGridView g = sender as ASPxGridView;
        e.Cancel = true;
    protected void grid_RowInserting(object sender, ASPxDataInsertingEventArgs e) {
        CustomDataSourse.Rows.Add(e.NewValues["Id"], e.NewValues["Data"]);

        ASPxGridView g = sender as ASPxGridView;
        e.Cancel = true;

    private void CreateGrid() {
        ASPxGridView grid = new ASPxGridView();
        grid.ID = "grid";

        grid.EnableCallBacks = false;
        grid.KeyFieldName = "Id";

        grid.DataBinding += grid_DataBinding;
        grid.RowDeleting += grid_RowDeleting;
        grid.RowUpdating += grid_RowUpdating;
        grid.RowInserting += grid_RowInserting;
        grid.DataBound += grid_DataBound;
        grid.RowValidating += new ASPxDataValidationEventHandler(grid_RowValidating);
        if (!this.IsPostBack) {
            GridViewCommandColumn c = new GridViewCommandColumn();

            c.EditButton.Visible = true;
            c.UpdateButton.Visible = true;
            c.NewButton.Visible = true;
            c.DeleteButton.Visible = true;
            c.CancelButton.Visible = true;

        GridViewDataTextColumn col = grid.Columns["Id"] as GridViewDataTextColumn;
                                                                            = "\\d{1,9}";

    void grid_RowValidating(object sender, ASPxDataValidationEventArgs e) {       
        int id = (int)e.NewValues["Id"];
        if ((!e.OldValues.Contains("Id") || ((int)e.OldValues["Id"] != id))
            && (CustomDataSourse.Rows.Find(id) != null)) {
            ASPxGridView grid = sender as ASPxGridView;
            e.Errors[grid.Columns["Id"]] =
String.Format("Column 'Id' is constrained to be unique.  Value '{0}' is already present.", id);
    private void UpdateData(ASPxGridView g) {
        ViewState["CustomTable"] = dataTable;

.Net - 10th Anniversary

It was in June, 2000 that Bill Gates proclaimed the dawn of the new Internet and, with it, the
announcement of one platform to rule them all - .Net. Ten years later
Ten years ago, Microsoft
announced its vision for a unified programming environment to support next-generation applications. 
Finally releasing the framework 2.5 years later in .Net 1.1, Microsoft started down a road that (for
better or worse) changed the Windows development paradigm to allow multiple flavors of languages,
but one "engine" at runtime.  

With their announcement of Microsoft .Net 4, this article takes a look back at the road that
got us here.

"What is .NET?" Ballmer said. ".NET represents a set, an environment, a programming infrastructure
that supports the next generation of the Internet as a platform. ... It is also, though, and Bill [Gates]
made the analogy, I think, with Windows here pretty well for its day, .NET is also a user environment,
a set of fundamental user services that live on the client, in the server, in the cloud, that are consistent
with and build off that programming model. So, it's both a user experience and a set of developer
experiences, that's the conceptual description of what is .NET."

It's interesting that we are listening about the word "cloud", all the way back in 2000 before cloud
computing was a commonly discussed set of technologies. But in the decade since then, it was really
Google and Amazon that became the poster child vendors for the evolution of the Internet and cloud
computing services for businesses and developers.

Microsoft's cloud vision, and .NET in particular, relies on Windows, of course, whereas much of the rest
of the cloud computing world is based on open source technologies such as Linux and Xen virtualization.

.NET's first release occurred on Feb. 13, 2002, a year and a half after it was announced, and the latest
version - .NET Framework 4 - was released just two months ago.

Monday, August 22, 2011

Crystal Reports in Microsoft Visual Studio 2010 and issues for depoymentment

Microsoft Visual Studio 2010 no longer includes Crystal Reports in the bundle.

In Visual Studio 2010, to create a Crystal Reports project or Web site or to import existing projects
or Web sites that were created by using older versions of Visual Studio or Crystal Reports, you must
first install a version of Crystal Reports that is compatible with Visual Studio 2010.

For more information about how to use Crystal Reports in Visual Studio 2010, visit the following SAP
Crystal Reports website:

Developers can use Crystal Reports for Visual Studio to do the following:

  • Design unlimited reports for use in Visual Studio applications with the integrated Crystal Reports designer.
  • Integrate the Crystal Reports run time engine into thick client Microsoft Windows applications.
    • Thick client applications with the embedded run time engine can be freely redistributed both within
      and outside the developers' own organization.
  • Integrate the Crystal Reports run time engine into Web applications.
    • Web applications with the embedded run time engine can be freely redistributed within the developers ' own organization.
Microsoft provides third-party contact information to help you find technical support. This contact information may
change without notice. Microsoft does not guarantee the accuracy of this third-party contact information.

The following visual studio addons for using crystal are available here.
  • Standard EXE installation package which installs SAP Crystal Reports for Visual Studio into the
    Visual Studio 2010 IDE.
  • Click-Once installation package used to create self-updating Windows-based applications which
    can be installed and run with minimal user interaction..
  • Merge Modules installation package used to install components which are shared by multiple
  • Redistributable installation (32 bit).
  • Redistributable installation (64 bit).
I hope this saves some time for you.

Sunday, August 21, 2011

Database Publishing Wizard in VS 2010 Professional

SQL Database Publishing Wizard" should be one feature named "Publish to Provider" in Visual Studio IDE as
the following screen shot:
this is great that Visual Studio 2010 have Publishing Wizard version 1.4 but on Microsoft website version 1.1
is available.
I have Visual Studio 2010 Ultimate installed on your machine. When I right click on any database in Server Explorer
, I can find "Publish to Provider" option listed.

After some search, I found:
In Visual Studio 2010, "SQL Database Publishing Wizard" feature should be installed as one component named
Microsoft SQL Publishing Wizard 1.4 during the installation.
It should be located at the path: C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\1.4\sqlpubwiz.exe.