Showing posts with label Programming General. Show all posts
Showing posts with label Programming General. Show all posts

Monday, 12 November 2012

Free Microsoft Learning Events by Microsoft Learning Partners

Click on the link below to find some of the third-party events where you can learn about Microsoft technologies.

http://www.microsoft.com/learning/en/us/community/events.aspx

Microsoft Tech Showcase: Technology events hosted by Microsoft Learning Partners

You can search events based on your technology, country, City/Province, Online/In Person events, From Date, To Date and name of the partners. These events will help you to boost your careers, learn new technologies, etc all free of cost.

Share:

Friday, 10 October 2008

C# Coding Standards

Following the right Coding standars comes with Practice and proper Guidance if you are a starter, and also lots of companies define or customize their own coding standards.

When I came across this challange to define the coding standard for my team, I thought instead of reinventing the wheel and recollecting everything from my experience, better if I get something which is already defined and documented. So I started googling and came across a very good document which covers almost all the aspects of C# Coding standards which I was looking for. This Document covers the following topics*

  • Cover all major C# Language features.
  • Provide guidelines on coding style & language usage (but not syntax)
  • Demonstrate all rules in code where applicable.
  • Describe rules in structure that is easy to read & use.
  • Define clear & concise rules.
  • Use consistent terminology & rule patterns.
  • Only provide rules where there is a clear cut best practice.
  • Lead developers to a "pit of success" and avoid common "pits of failure"
  • You can download the PDF from here http://weblogs.asp.net/lhunt/attachment/591275.ashx

    Original Post you can find here : http://weblogs.asp.net/lhunt/pages/CSharp-Coding-Standards-document.aspx

    Thanks

    ~Brij

    * All the Copyrights in this Post are the property of the Respective Owner.

    Share:

    Tuesday, 2 September 2008

    Troubleshooting Visual Studio 2005 and Visual Studio 2008 On Windows Vista

    With the introduction of IIS 7.0 in windows vista number of people have been reporting problems when trying to debug their ASP.NET applications on Windows Vista with Visual Studio 2005 F5 debugging support.  There are a handful of posts about trying to get this to work in various ways.

    I also faced similar issues. As there are already some good articles floating on net, so instead of reinventing the wheel, I am giving below the links to those articles here. This post I am publishing for my reference only, but if you found this article then I hope this will provide you too with one stop solution to most of the issues. And if you have any good articles then please post as comment.

    Fix problems with Visual Studio F5 debugging of ASP.NET applications on IIS7 Vista

    Explore The Web Server For Windows Vista And Beyond

    Using Visual Studio 2008 with IIS 7.0

    Tip/Trick: Using IIS7 on Vista with VS 2005

    For me just the first link was more then enough, but for your knowledge I think every link has got some unique combination of knowledge which may help you, and save you time googling with flooded search result.

    Cheers

    ~Brij
    Share:

    Sunday, 31 August 2008

    Installing Sharepoint Services 3.0 on Windows Vista OS

    Just few days back I started exploring Sharepoint Technologies, and started thinking where to start. The biggest setback for me was I cannot run Sharepoint Services on my windows Vista System because Sharepoint Services can only be installed on Windows Server Family of Operating System. But now I cannot go back and repartition my System and install Sharepoint, I also tried using Windows Virtual Machine, but Windows Server 2003 was not working properly on my Windows Virtual Machine.

    So now I am left with only two option either repartition the whole harddisk and install dual boot OS or Find some way to run windows sharepoint services on my windows vista. So I started googling and finally I found a jackpot where I can install sharepoint on Windows Vista. First I thought its one more bluff, but thought to give a try, and it worked, and now I am using Windows Sharepoint Services on my Windows Vista Ultimate OS.

    Just follow the link below which will guide you step by step process how to do that.

    http://community.bamboosolutions.com/blogs/bambooteamblog/archive/2008/05/21/how-to-install-windows-sharepoint-services-3-0-sp1-on-vista-x64-x86.aspx

    To download the setup helper file you can either download from the above link or you can download from here directly.

    Cheers

    ~Brij
    Share:

    Friday, 29 August 2008

    Refreshing the Data in ObjectDataSource Dynamically

    In my previous post, you have seen the paging example, but there is one small problem you may face, if you are using ControlParameter or QueryStringParameter, for instance take a scenario when you are using ASP.NET AJAX and you have GridView and Search button in update panel.

    On page load, the ObjectDataSource will take the default parameters from the DropDownList and QueryString, but problems comes when we want to click Search Button to get the changed values of the DropDownList or the QueryString without posting the page again.

    Generally to refresh the data of ObjectDataSource you often write

    ObjectDataSource1.Select();

    On Click of Search Button.

    But hold on this is only good if you want to see the changed data from the database or Rebind the ObjectDataSource, but this will not pass the current value from the controls or query string as a parameter to the database Query or Procedure. Resulting in which you will keep getting the existing query result only, so here is the actual code below for which I have written such a big story.

    GridView1.DataBind();

    Yes just one line code, don't worry this internally calls the ObjectDataSource1.Select(), but will give you the desired result, I hope this will help you.

    Thanks

    ~Brij
    Share:

    ASP.NET Custom Paging with GridView using ObjectDataSource

    Paging is perhaps one of the most required in data presentation, specially when it comes to huge amount of data, normal paging becomes nightmare. If you are developing your application using ASP.NET 2.0, then you can make use of ObjectDataSource in a very efficient manner to achieve paging.

    The code which I am providing below will give you a complete understanding of how you can do this, this technique will fetch one the number of data which you set in PageSIze of GridView from the DataBase, instead of fetching entire data and on every PageIndexChanged event repeating the full cycle again,

    First you need to either modify or write your procedure the input and output parameters which will fit into your .NET code to get the paging.

    create procedure proc_EmployeeDetails
    @empId int,
    @empStatus varchar(10),
    @pagestart int = null,
    @pagesize int = null,
    @numresults int output
    as

    create table #empresults
    (
    [rowid] [int] IDENTITY (1, 1) NOT NULL,
    [empID] [nchar] (5) ,
    [EmpName] [nvarchar] (30),
    [Address] [varchar] (200),
    [DOB] [datetime],
    [Age] [int],
    )


    insert into #empresults (empid, empname, address, DOB, Age)
    select empID, EmpName, Address, DOB, Age
    where
    empid = @empId AND empStatus = @empStatus
    order by EmpName

    set @numresults = @@rowcount

    if @pagesize is null
    set @pagesize = @numresults

    if @pagestart is null
    set @pagestart = 1

    set rowcount @pagesize

    select *
    from #empresults
    where rowid >= @pagestart

    drop table #tempresults





    Next I create a Employee class which will hold the results from the database.




    public class EmployeeCollection : IList<Employee> { }

    public class Employee
    {
    private int _empId;
    private string _empName;
    private DateTime? _DOB;
    private int _age;
    private string _address;

    public Employee() { }

    public int EmployeeId
    {
    get { return _empId; }
    set { _empId = value; }
    }

    public string EmployeeName
    {
    get { return _empName; }
    set { _empName = value; }
    }

    public DateTime? DOB
    {
    get { return _DOB; }
    set { _DOB = value; }
    }

    public int Age
    {
    get { return _age; }
    set { _age = value; }
    }

    public string Address
    {
    get { return _address; }
    set { _address = value; }
    }

    }





    Now as we have got the BusinessObjects, it time to create a class specifically designed to handle request from ObjectDataSource. This class you can keep in your app_code directory of web project and is used like facade layer between UI layer and Business Layer.




    Excuses for the code formatting, but you got the idea what I mean to say, right ?




    public class EmployeeDataSource
    {
    public EmployeeDataSource() { }

    public int SelectCount(int empId, string employeeStatus, ObjectDataSourceSelectingEventArgs e)
    {
    return e.Arguments.TotalRowCount;
    }

    public EmployeeCollection Select(int empId, string employeeStatus, int maximumRows, int startRowIndex, ObjectDataSourceSelectingEventArgs e)
    {
    using (SqlConnection connection = new SqlConnection("Initial Catalog=Employee;Integrated Security=SSPI;Data Source=."))
    using (SqlCommand command = new SqlCommand("proc_EmployeeDetails", connection))
    {
    connection.Open();
    command.CommandType = CommandType.StoredProcedure;
    command.Parameters.AddWithValue("@empId", empId);
    command.Parameters.AddWithValue("@empStatus", employeeStatus);
    command.Parameters.AddWithValue("@pagestart", startRowIndex);
    command.Parameters.AddWithValue("@pagesize", maximumRows);
    command.Parameters.Add(new SqlParameter("@numresults", SqlDbType.Int, 0, ParameterDirection.Output, false, 0, 0, null, DataRowVersion.Default, 0));
    EmployeeCollection employees = new EmployeeCollection();
    using (SqlDataReader reader = command.ExecuteReader())
    {
    while (reader.Read())
    {
    Employee emp = new Employee();
    emp.EmployeeId = reader.GetInt32("empId");
    emp.EmployeeName = reader.GetString("empname");
    emp.DOB = reader.GetDateTime("DOB");
    emp.Age = reader.GetInt32("Age");
    emp.Address = reader.GetString("Address");
    employees.Add(emp);
    }
    }
    e.Arguments.TotalRowCount = (int)command.Parameters["@numresults"].Value;
    return employees;
    }
    }





    Now I am adding code to the code behind of the EmployeeDetails.aspx page.



    protected void objectDataSourceOrders_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
    {
    if (!e.ExecutingSelectCount)
    {
    e.Arguments.MaximumRows = this.gridViewEmployees.PageSize;
    e.InputParameters.Add("e", e);
    }
    }

    Here is the ASPX page code that goes along with the rest of this example




    <body>
    <
    form id="form1" runat="server">
    <
    div>
    <
    asp:DropDownList ID="ddlEmpStatus" runat="server">
    <
    asp:ListItem Text="Active" Value="Active" Selected="True"></asp:ListItem>
    <
    asp:ListItem Text="Disabled" Value="Disabled"></asp:ListItem>
    </
    asp:DropDownList>
    </
    div>
    <
    div>
    <
    asp:GridView ID="gridViewEmployees" runat="server" AllowPaging="True" AutoGenerateColumns="False"
    CellPadding="2" DataSourceID="objectDataSourceEmployee" ForeColor="Black" GridLines="None" BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px">
    <
    FooterStyle BackColor="Tan" />
    <
    Columns>
    <
    asp:BoundField DataField="EmployeeId" HeaderText="ProductId" SortExpression="ProductId" />
    <
    asp:BoundField DataField="EmployeeName" HeaderText="ProductName" SortExpression="ProductName" />
    <
    asp:BoundField DataField="DOB" HeaderText="UnitPrice" SortExpression="UnitPrice" />
    <
    asp:BoundField DataField="Age" HeaderText="CustomerId" SortExpression="CustomerId" />
    <
    asp:BoundField DataField="Address" HeaderText="OrderId" SortExpression="OrderId" />
    </
    Columns>
    <
    SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
    <
    PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
    <
    HeaderStyle BackColor="Tan" Font-Bold="True" />
    <
    AlternatingRowStyle BackColor="PaleGoldenrod" />
    </
    asp:GridView>
    <
    asp:ObjectDataSource ID="objectDataSourceEmployee" runat="server" EnablePaging="True"
    SelectMethod="Select" TypeName="EmployeeDataSource" OnSelecting="objectDataSourceOrders_Selecting" SelectCountMethod="SelectCount">
    <
    SelectParameters >
    <
    asp:QueryStringParameter QueryStringField="empid" DefaultValue="0" Name="empId" />
    <
    asp:ControlParameter ControlID="ddlEmpStatus" DefaultValue="Active" Name="employeeStatus" PropertyName="Value" />
    </
    SelectParameters>
    </
    asp:ObjectDataSource></div>
    </
    form>
    </
    body>


    In the aspx page I am passing the Query string and dropdown control value as a parameter, and Binding the result to the GridView.





    The code above worked for me, I hope you too find this code useful.





    Thanks


    ~Brij
    Share:

    Tuesday, 19 August 2008

    Versioning ASP.NET 2.0 WebSite Assembly / Web Deployment Project

    The web project model changed in number of ways from Visual Studio 2003 to Visual Studio 2005, But one major part which is missing is the ability to version the assembly using AssemblyInfo.cs file.

    This is because the model of VS 2005 dynamically creates multiple assemblies for each class file. Resulting in which we cannot have single named assembly to set version number.

    We cannot change the default behaviour of compilation but we can change the way we can deploy our project files and assemblies, by using Web Deployment Project.

    Microsoft Web Deployment Project adds numerous features which nicely integrates with Visual Studio 2005, out of which the most useful I found is:

    More control over number of assemblies generated by a pre-complied web application as well as control over the naming of the output assemblies. Which means you can generate either single assembly for you entire project, and select the name and version you want for e.g Foo.dll, etc or generate the assemblies per directory/ pages or control.

    The ability to customize and modify the web.config file during deployment, that means you need not to change you web.config file every time before making release or deploying the project, instead you can specify the web.config keys on Web Deployment project, that you use for deployment, like this you can customize any other web.config settings also.

    These are the few things which I named here, if you want more information on how to install, and use this you can visit the Scott's Blog from the below link:

    http://weblogs.asp.net/scottgu/archive/2005/11/06/429723.aspx

    Or you can Download the VS 2005 Web Deployment Project from

    WebDeploymentSetup.msi

    Other Useful Links which may help you to further explore this subject

    http://msdn.microsoft.com/en-us/library/aa479568.aspx

    Web Deployment Projects Forum

    I hope this will help you, if you have something to share on this topic, then please leave a comment.

    Thanks

    ~Brij

    Share:

    Tuesday, 12 August 2008

    IsNumeric Function in C#

    VB.NET has lots of functions that C# developers have to create manually.

    Out of which I am providing here the different alternatives of IsNumeric function of VB.NET in C#

    Using Parse

    static bool IsNumeric(string s)

    {

        try

        {

            Int32.Parse(s);

        }

        catch

        {

            return false;

        }

        return true;

    }

    Using Double.TryParse

    (C# 2.0 and above)

    static bool IsNumeric(object expression)

    {

        if (expression == null)

            return false;

        double number;

        return Double.TryParse(Convert.ToString(expression,   CultureInfo.InvariantCulture),

            System.Globalization.NumberStyles.Any, NumberFormatInfo.InvariantInfo, out number);

    }

    Using Regular Expression

    bool IsNumeric(string value)

    {

        Regex regxNumericPatters = new Regex("[^0-9]");

        return !regxNumericPatters.IsMatch(value);

    }

    OR

    static bool IsNumeric(string inputString)

    {

        return Regex.IsMatch(inputString, "^[0-9]+$");

    }

    Using Char

    static bool IsNumeric(string numberString)

    {

        foreach (char c in numberString)

        {

            if (!char.IsNumber(c))

            return false;

        }

        return true;

    }

    I hope this will help you, if you have more ideas then do write comments.

    Share:

    Wednesday, 23 July 2008

    Visual Studio .NET 2005 Keyboard Shortcuts

    Visual Studio 2005 is a great IDE to develop .NET applications. But If we don't know the keyboard shortcut for some function we have to do it with mouse and it will take lots of time.


    I have found a great link which contains almost all the short cut for keyboards.


    Here is the link for that article...

    http://www.codinghorror.com/blog/files/Visual%20Studio%20.NET%202005%20Keyboard%20Shortcuts.htm

    Share:

    Change default Port for the ASP.NET Development Server

    When you use the ASP.NET Development Server to run a file-system Web site, by default, the Web server is invoked on a randomly selected port for localhost. For example, if you are testing a page called Default.aspx, when you run the page on the ASP.NET Development Server, the URL of the page might be the following:

    http://localhost:3499/Default.aspx

    To specify a port for the ASP.NET Development Server
    1. In Solution Explorer, click the name of the application.

    2. In the Properties pane, click the down-arrow beside Use dynamic ports and select False from the dropdown list.

      This will enable editing of the Port number property.

    3. In the Properties pane, click the text box beside Port number and type in a port number.

    4. Click outside of the Properties pane. This saves the property settings.

      Each time you run a file-system Web site within Visual Web Developer, the ASP.NET Development Server will listen on the specified port.

    Please note the above steps are based on WebSite/ WebServices project. For the Web Application project, we can fix the port number by following steps:

    1.  Right click the Project in the Solution Explorer, and then select “Properties”
    2.  Click “Web” tab.
    3.  Check “Specific port” instead of “Auto-assign Port”.

    If you want to debug with IIS, please follow the first and second steps above, and then check “Use IIS Web Server” instead of “Use Visual Studio Development Server”. Also, click the “Create Virtual Directory” button.

    Note:

    Visual Web Developer cannot guarantee that the port you specify will be available when you run your file-system Web site. If the port is in use when you run a page, Visual Web Developer displays an error message.

    Share:

    Friday, 18 July 2008

    Method Overloading in WebServices

     

    Web services are also classes just like any other .NET classes. Nevertheless they have methods marked as WebMethods that can be exposed by the WebServices to be consumed by the outside world. Apart from these WebMethods they can also have normal methods like any other classes have.


    Since a web service is a class it can utilize all the OO features like method overloading. However to use this feature on WebMethods we need to do something more that is explained in this article.

    Creating WebMethods:


    Let us create a simple WebService that has the following overloaded methods:
    public int AddNumbers(int a, int b)

    public int AddNumbers(int a, int b, int c)

    public decimal AddNumbers(decimal a, decimal b)

    All these three methods return variants of a Added numbers to the WebClient. Let us now mark the methods as Web Methods. To acheive this apply the [WebMethod] attribute to the public methods.

    [WebMethod]

    public int AddNumbers(int a, int b)

        return a+b;

    }

    [WebMethod]

    public int AddNumbers(int a, int b, int c)

        return a+b+c;

    }

    [WebMethod]

    public decimal AddNumbers(decimal a, decimal b)

    {

        return a+b;

    }

    This would compile fine. Run the WebService in the browser. That should give an error saying that the AddNumbers() methods use the same message name 'AddNumbers' and asking to use the MessageName property of the WebMethod.

    Adding the MessageName property:

    Add the MessageName property to the WebMethod attribute as shown below:

    [WebMethod]

    public int AddNumbers(int a, int b)

        return "a+b";

    }

    [WebMethod (MessageName="AddThreeNumbers")]

    public int AddNumbers(int a, int b, int c)

        return a + b + c;

    }

    [WebMethod (MessageName="AddDecimal")]

    public decimal AddNumbers(decimal a, decimal b)

    {

        return a+b;

    }

    Now compile the WebService and run in the browser. You can see that the first method is displayed as AddNumbers wherein for the second and third method the alias we set using the MessageName property is displayed.

    Share:

    Thursday, 15 May 2008

    Javascript Date Comparision using CustomValidator And String to Date Conversion using JavaScript

    This function calculates the difference between the two Date, and Validate it,

    I used this function to validate the difference between the From Date and To Date for not more then 366 days(to cover the leap year also) or less then 0,

    This function is called through the CustomValidator of ASP.NET, but you can also use this without the CustomValidator.

    <asp:CustomValidator runat="server" ID="custDateValidator"

    ClientValidationFunction="CompareDates" Display="Dynamic"

    ErrorMessage="The number of date to be included in report must be between 1 and 366">

    </asp:CustomValidator>

    This piece of code also depicts how we can convert the String to DateTime, because in my form I am taking the Dates from two HTML TextBoxes, which by default is String, so I had to write seperate piece of code which will convert String to DateTime.

    <script language="JavaScript">

    function CompareDates(source, args) {

    var fromDate = new Date();

    var txtFromDate = document.getElementById("txtDateFrom").value;

    var aFromDate = txtFromDate.split("/");

    /*Start 'Date to String' conversion block, this block is required because javascript do not provide any direct function to convert 'String to Date' */

    var fdd = aFromDate[0]; //get the day part

    var fmm = aFromDate[1]; //get the month part

    var fyyyy = aFromDate[2]; //get the year part

    fromDate.setUTCDate(fdd);

    fromDate.setUTCMonth(fmm-1);

    fromDate.setUTCFullYear(fyyyy);

    var toDate = new Date();

    var txtToDate = document.getElementById("txtDateTo").value;

    var aToDate = txtToDate.split("/");

    var tdd = aToDate[0]; //get the day part

    var tmm = aToDate[1]; //get the month part

    var tyyyy = aToDate[2]; //get the year part

    toDate.setUTCDate(tdd);

    toDate.setUTCMonth(tmm-1);

    toDate.setUTCFullYear(tyyyy);

    //end of 'String to Date' conversion block

    var difference = toDate.getTime() - fromDate.getTime();

    var daysDifference = Math.floor(difference/1000/60/60/24);

    difference -= daysDifference*1000*60*60*24;

    //if diffrence is greater then 366 then invalidate, else form is valid

    if(daysDifference > 366 daysDifference < 0)

    args.IsValid = false;

    else

    args.IsValid = true;

    }

    </script>

    I Hope this will Help.

    Share:

    Thursday, 8 May 2008

    Running Multiple Version of IE in same System

    If you ever been working on layout and design of website then you may need to test the layout and rendering of the website in different browser, like IE 7, IE 6, IE 5.5, FireFox, Opera, etc.

    But normally it is not possible to install multiple version IE in same system. So to get through this limitation of Windows, I found the following program using this you can run multiple version of IE (IE 7.0, 6.0, 5.5, 5.1, 4.0, 3.0) in the same System,

    Download it

    Normally this installer will not work with Windows Vista,

    Follow the progress of running Internet Explorer 6 natively on Windows Vista here!

    You can get more details in Treadsoft Homepage

    I hope this will help you.

    Share:

    Saturday, 19 April 2008

    Disable right mouse click, Disable Browser Back Button

    Sometime our application demands to change some of the normal workflow of the Browsers. Here are the few tweaks in programming which may help you to do that.

    Do not allow user to view page using browser back button.

    <%Response.Cache.SetCacheability(HttpCacheability.NoCache); %>

    Disable Right Click

    This is a cross browser DHTML script that will prevent the default right menu from popping up when the right mouse is clicked on the web page. Use it to stop surfers from easily saving your web page, viewing its source, or lifting images off your site when using either IE 4+ or NS 4+.

    <script language=JavaScript>
    <!--

    var message="Function Disabled!";

    ///////////////////////////////////
    function clickIE4(){
    if (event.button==2){
    alert(message);
    return false;
    }
    }

    function clickNS4(e){
    if (document.layersdocument.getElementById&&!document.all){
    if (e.which==2e.which==3){
    alert(message);
    return false;
    }
    }
    }

    if (document.layers){
    document.captureEvents(Event.MOUSEDOWN);
    document.onmousedown=clickNS4;
    }
    else if (document.all&&!document.getElementById){
    document.onmousedown=clickIE4;
    }

    document.oncontextmenu=new Function("alert(message);return false")

    // -->
    </script>

    Share:

    Dotnet 2.x Debugging Links

    Lots of successful programming depends on how Good you are in debugging, everyone of us tends to make mistake while programming but if you are good in debugging then you can save lots of your precious time and frustrations. I found couple of good links which gives you very good understanding in debugging in .net technologies.

    http://www.charlescarroll.com/chaz/site/4302/default.aspx

    http://www.charlescarroll.com/chaz/site/4810/default.aspx

    http://community.strongcoders.com/r.ashx?O

    Links related to debugging/viewing  ViewState

    Bringing ViewState into the Light

    Mole v4.2 - Visualizer With Property Editing,

    Mole For Visual Studio - Visualizer For All Project Types

    Related: ViewState property code snippet

    I hope this will help you, if also know some good sites then do share with me here in comments.
    Share:

    Friday, 8 February 2008

    Programming with Google Maps API

    The Google Maps API lets you embed Google Maps in your own web pages with JavaScript. The API provides a number of utilities for manipulating maps (just like on the http://maps.google.com web page) and adding content to the map through a variety of services, allowing you to create robust maps applications on your website.

    How do I start?

    1. Sign up for a Google Maps API key.
    2. Read the Maps API Concepts.
    3. Check out some Maps examples.
    4. Read the Maps API Reference.

    Google Maps API Examples

    All of the examples contained within the Google Maps API documentation set are listed below for quick reference.

    Map Examples

    Event Examples

    Controls Examples

    Marker Examples

    Polyline Examples

    Polygon and Tile Overlay Examples

    Custom Overlay Examples

    Services Examples

    Featured Video

    These are just the few links and introduction of Google Map API, very soon I wil post my sample project using Google Map API,

    You can also get the map API class reference at Google MAP API Class Reference

    And you can get the full documentation and downloadable examples and reference at Google Maps API

    Share: