Surendra Sharma

Surendra Sharma

Search This Blog

Friday, June 28, 2013

How to get autoincrement assembly version for ASP.NET website

In ASP.NET, developer can not assign assembly version to web site. However they can get assembly version info from console, windows, class library, web applications.

There is one way to get auto increment for assembly version for website.
Create blank solution, add web site project into it.

Add one class library to this solution from File -> Add -> New Project -> Class Library



Write a method which return assembly version of this class library as below

Open “AssemblyInfo.cs” file and paste following code

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ClassLibrary1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ClassLibrary1")]
[assembly: AssemblyCopyright("Copyright ©  2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components.  If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("e6761a90-b4a8-42cf-a455-c47a240dd8eb")]

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("2.0.*")]

namespace ClassLibrary1
{
    public partial class AssemblyInfo
    {
        /// <summary>
        /// Get version numbers from Assembly
        /// </summary>
        /// <returns></returns>
        public static string GetAssemblyVersion()
        {
            var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            return string.Format("{0}.{1}.{2}.{3}", version.Major, version.Minor, version.Build, version.Revision);
        }
    }
}

Add reference of this class library in website project.

Write following code to get assembly version.

protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "Version " + ClassLibrary1.AssemblyInfo.GetAssemblyVersion();
}



Now everytime you rebuild your solution, you will get different assembly version.

Thursday, June 27, 2013

Checklist for Outing / Trip / Picnic

1.    Decide place and date
2.    Inform all friends who are interested
3.    Collect money
4.    Take permissions of all the places from authorities
5.    Book Vehicle – bus
6.    Make arrangement for food
7.    Collect personal info of all members – Name, Contact number, Address, email id, emergency contact number
8.    Get vehicle details and driver info with contact number
9.    Get route map from source to destination
10. Always wear comfortable dress – Avoid jeans and tight clothes
11.  Sport Shoes – recommended
12. Avoid high heels sandal, loose chappals
13. Extra pair of dresses, chappals
14. Packed snacks - dry fruits, chiwda, farsan, biscuits, fruit cakes
15. Paper plates
16. Water bottle – **** Most important
17. Towel and napkin
18. Goggle, cap, scarf
19. Sweeter for winter or raincoat during rainy season
20. Umbrella
21. Camera
22. Torch
23. Sunscreen cream – If going to play in water
24. Mobile – Charge it a day before
25. Cash Money
26. Medicines
27. Identity proof
28. Garbage bags – Don’t though wastes at road or destination
29. Poly bags – Useful to keep wet clothes in rainy season
30. Small polythin – Can keep mobile, money, identity proof in rainy season
31. Remember or keep any telephone number on paper in case of mobile lost
32. Same dress code - It’s very easy to identify each other
33. Paper Soap *** or liquid soap – In most of the food place you will never get any soap


I added all the possible items. Please suggest if I am missing anything.
If you feel it’s useful for you, please mark below or leave comments.

How to assign function output to table variable

I have Split function and want to store its output to table varaibale.

DECLARE @ParsedTable AS TABLE (Item VARCHAR(MAX)) ;
INSERT @ParsedTable SELECT * FROM dbo.Udf_split('505,468',',');
SELECT * FROM Employee WHERE  userid IN (SELECT * FROM   @ParsedTable)
 
     
-- =============================================    
-- Description:  Used for Spliting the list    
-- =============================================    
CREATE FUNCTION [dbo].[Udf_split] (@List  VARCHAR(max), @Delim CHAR)    
returns @ParsedTable TABLE (Item VARCHAR(max))    
AS    
  BEGIN    
      DECLARE @list1 VARCHAR(max),@Pos INT, @rList VARCHAR(max)    
   
      SET @list = Ltrim(Rtrim(@list)) + @Delim    
      SET @pos = Charindex(@delim, @list, 1)    
   
      WHILE @pos > 0     
        BEGIN    
            SET @list1 = Ltrim(Rtrim(LEFT(@list, @pos - 1)))    
   
            IF @list1 <> ''    
              INSERT INTO @ParsedTable VALUES (Cast(@list1 AS VARCHAR(max)))    
   
            SET @list = Substring(@list, @pos + 1, Len(@list))    
            SET @pos = Charindex(@delim, @list, 1)    
        END    
   
      SELECT @rlist = COALESCE(@rlist+',', '') + item FROM (SELECT DISTINCT Item FROM @ParsedTable) t    
   
      RETURN    

  END

How to get random records in Sybase IQ and SQL Server

Use Rand(PrimaryKey) function to get random number along with milliseconds as below


SELECT TOP 5 * FROM Employee Order by RAND( CONVERT(BIGINT,RAND(ID)*1000000000) - DATEPART( Millisecond   ,GETDATE()))

Dunkirk Line Post Office, Pune 411014

Yesterday I got message from Post Office that I received one speed post letter, collect it from Dunkirk Line Post Office, Pune - 411014 within 2 days.

First problem was message was in worst handwriting that nobody understands what the actual address he mentioned is.

Second, anybody doesn’t know about where is Dunkirk Line Post Office.


Thanks to GOOGLE. Finally I was able to view in Google maps.



View Larger Map

It is inside Air Force area.

I never visited before there. I always thought it’s a restricted area.

When you visit from Vimannagar to Chandannagar, at Chandannagar 2nd square [Near to toll tax kind of stuff], take left.

This is the second gate of entrance in Air Force Zone. Go inside.

Security guards will ask you about purpose, ID card.

Make entry in their register.

If you have bike, keep helmet with you otherwise you have walk almost 1 km.
Four vehicles are not allowed inside military premises.

After making entry, go straight [till road end], take left. At last you come in front of Canteen. Park you bike in parking area.

Dunkirk Line Post Office is behind military canteen. Beside SBI ATM [Don’t confuse with ATM. Actually there are two SBI ATM. First ATM inside first entrance gate. Don't go there. Visit to second ATM.]

Always visit post office between 9-11 AM.

I don't understand why government offices are not making people life easier. Whats the use of post office inside military zone for common man?

Monday, June 24, 2013

How to avoid postback on ENTER key press in textbox or How to block ENTER key press in textbox

$(document).ready(function() {

    // Block ENTER key in textbox
    $('#txtSearch').keypress(function(event) {
        if ((event.keyCode || event.which) == 13) {
            event.preventDefault();
            return false;
        }
    });

})

Thursday, June 20, 2013

Find checkbox in row of each grid using JQuery

if ($(grd.rows[i]).find("input[id*='chkDatabase']:checkbox").attr('checked') == true) {
grd.rows[i].style.display = '';
}
else
{
grd.rows[i].style.display = 'none';

}

Get value from Textbox and convert it into upper or lower case in Jquery

//Get value from textbox and convert in UPPER case
var searchStr = $('#txtSearch').val().toUpperCase();

//Get value from textbox and convert in lower case

var searchStr = $('#txtSearch').val().toLowerCase();

Friday, June 14, 2013

How to Auto Increment Build/Version Numbers of Visual Studio Project and get in C#

Open "AssemblyInfo.cs"

Version information for an assembly consists of the following four values:

      Major Version
      Minor Version
      Build Number
      Revision

You can specify all the values or you can default the Revision and Build Numbers
by using the '*' as shown below:

Replace line
[assembly: AssemblyVersion("1.0.0.0")]
with
[assembly: AssemblyVersion("1.0.*")]

Remove or comment out below line
[assembly: AssemblyFileVersion("1.0.0.0")]

Here 1.0.0.0 Means [Major].[Minor].[Build].[Revision],

Now you should get new version number after each time you rebuild project.
C# code to get version number

var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
Label1.Text = string.Format("v{0}.{1}.{2} ({3})", version.Major, version.Minor, version.Build, version.Revision);

When to change each number?
  • Major number when a core piece of the app is rewritten or reworked.
  • Minor version when a new work order is processed
  • Auto increament or leave the build number at zero,
  • Auto increment the revision number every round of testing

In case of auto increament,

  • Build number is the number of days since Dec 31, 1999. 
  • The Revision number is the number of seconds since midnight, divided by 2.

Wednesday, June 12, 2013

How to configure Sybase IQ

a.       Start installation of “Setup” file iq1540_nc_win32_2
Note: - During installation select License copy as option
b.      Create ODBC DSN connection for Sybase IQ from Control Panel -> All Control Panel Items -> Administrative Tools -> Data Sources(ODBC) -> System DSN -> Click Add Button
                                                               i.      On ODBC tab, specify DataSource name = MyDataSource
                                                             ii.      On Login tab, specify
User=<Any User Name>
                Password=<Any Password>
                Action=Connect to a running database on another computer
                Host=<IP Address>
                Port=<Port number>
                Server=<Server Name>
                Database name=<DB Name>
                                                            iii.      Click on OK , OK
c.       Open Start -> Sybase -> Sybase IQ 15.4 -> Interactive SQL
In ODBC Data Source name, browse ODBC that we have created and click on Connect


d.      You can also access GUI based window of Sybase IQ with same steps from Start -> Sybase -> Sybase IQ 15.4 -> Sybase Central

Steps for accessing TFS

1.       Connect to VPN from Visual Studio from View -> Team Explorer.
2.       Try to access the code base using team foundation. Use the login credentials with domain name like “DomainNameXYZ\UserNameXYZ”. Please follow the following steps
a.       Go to team foundation server. Either through View -> Team explorer OR Tools -> connect to Team foundation server
b.      This will open one window where you can add server
c.       After you clicked on ‘Add Server’ it will open one window where you can add  URL “http://ServerLinkXYZ”

d.      Select any “ProjectXYZ” and map its “Trunk” folder with your local folder like “C:\ProjectXYZ\Code\Trunk”.

Calling base class constructor from derived class Constructor

If you want to call one constructor from another in a class itself, then use this()

If you want to call base class constructor from derived class constructor, then use base().

If you are not calling any base class constructor from derived class, then always base class default constructor will called.

Sample Program:

    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            DerivedClass objDerivedClass = new DerivedClass();
            //Output :  BaseClass - Default constructor
            //          DerivedClass - Default constructor

            DerivedClass objDerivedClass1 = new DerivedClass("PageId1234");
            //Output :  BaseClass - Default constructor
            //          DerivedClass - Default constructor
            //          DerivedClass - Overloaded constructor calling Default constructor using this()

            DerivedClass objDerivedClass2 = new DerivedClass(10800, "Student");
            //Output :  BaseClass - Overloaded constructor
            //          DerivedClass - Overloaded constructor calling base class constructor

            Console.ReadLine();

        }
    }

    public partial class BaseClass
    {
        int tempCommandTimeout = 0;

        /// <summary>
        /// Default constructor
        /// </summary>
        public BaseClass()
        {
           tempCommandTimeout = 300;
           Console.WriteLine("BaseClass - Default constructor");
        }

        /// <summary>
        /// Overloaded constructor to Set Command-timeout
        /// </summary>
        /// <param name="iCommandTimeout"></param>
        public BaseClass(int iCommandTimeout)
        {
            tempCommandTimeout = iCommandTimeout;
            Console.WriteLine("BaseClass - Overloaded constructor");
        }
    }

    public partial class DerivedClass : BaseClass
    {
        string TableName = "";
        string PageID = "";

        /// <summary>
        /// Default constructor
        /// </summary>
        public DerivedClass()
        {
            this.TableName = "Employee";
            Console.WriteLine("DerivedClass - Default constructor");
        }

        /// <summary>
        /// Overloaded constructor calling Default constructor using this()
        /// </summary>
        /// <param name="ePageID"></param>
        public DerivedClass(string ePageID)
            : this()
        {
            PageID = ePageID;
            Console.WriteLine("DerivedClass - Overloaded constructor calling Default constructor using this()");
        }

        /// <summary>
        /// Overloaded constructor calling base class constructor to Set Command-timeout
        /// </summary>
        /// <param name="iCommandTimeout"></param>
        public DerivedClass(int iCommandTimeout, string strTableName)
            : base(iCommandTimeout)
        {

            TableName = strTableName;
            Console.WriteLine("DerivedClass - Overloaded constructor calling base class constructor");
        }
    }