Sai Stuff to Developers

October 15, 2012

Converting a String to Title Case or Camel Case in C#

Filed under: DotNet — tosaik @ 6:28 am
Tags: , , ,

Now I am going to show how we can convert a string to a Title case or we also say it as Camel Case. For example I have a string as shown here

string name = "sai kUmar";

Now I need to convert the above string to Title case or we also say it as Camel Case, for this we have a special class called TextInfo which exist in the System.Globalization namespace. This special class has a special method called ToTitleCase() and which accepts only one string parameter and we need to pass our string need to convert through this parameter as shown below..

System.Globalization.TextInfo myTI = new System.Globalization.CultureInfo("en-US", false).TextInfo;
name = myTI. ToTitleCase(name);

Output: Sai Kumar

Note: Please provide your Current Culture while initializing TextInfo class object.

Hope this will helps you…

Happy Coding 🙂

September 20, 2012

Using jQuery allowing Only Alphanumeric Characters in a Textbox

Filed under: jQuery — tosaik @ 7:41 am
Tags: , , , ,


Need to restrict the users by entering other than Alphanumeric Characters, if any user enters Non- Alphanumeric Characters then need to trim those Characters and display a message beside the respective textbox saying only Alphanumeric Characters are allowed…



We have many solutions but using jQuery is the best way to achieve, with this we can use more flexible and reliable Regular expression technology with jQuery to achieve the above requirement.


Script Code:

 $(function () {


            $("[id*='txtFirstName']").keyup(function () {


                if (this.value.match(/[^a-zA-Z0-9 ]/g)) {
                    this.value = this.value.replace(/[^a-zA-Z0-9 ]/g, '');

HTML Code:

<asp:TextBox ID="txtFirstName" runat="server" Width="200px" CssClass="styled_input"></asp:TextBox>
<span id="span_txtFirstName" class="RegistrationNumericDiv">oops! Only AlphaNumberic Charecters are Accepted.</span>


In the above HTML Code is the normal code as I used asp.Net TextBox control to present this demo, but we can use any technology here as our browser parser can understand only HTML tags so every technology has their own parser to parse their respective language code to HTML code. Next line we have a SPAN tag which is used to hold the message to the user whenever user types a non-alphanumeric character in the respective textbox and this SPAN tag hide/show will be handled in the given jQuery code itself.

As we can see we use the regular expression to validate each character enter by the user and if anything wrong we replace those character(s) with empty string (‘’) and we show the message by toggling the  SPAN tag..

That’s it we are done with our requirement J

Thank you

Happy Coding J

September 17, 2012

Explaining briefly about OOP

Filed under: C++,OOPS Languages — tosaik @ 10:31 am
Tags: ,

The world can be considered to consist of many objects. Objects will have attributes and behaviors. A water-heater is a simple example of an object. It has certain attributes or properties (like color, size, maximum and current temperatures etc.) and there are certain behaviors associated with the water-heater (like switching on the heater, increasing the temperature or heating for a specified time interval, switching off the heater etc.). These are actions that can be performed on the heater. Or in other words they are actions which can modify certain properties of the heater (for instance by switching on the heater the current temperature of the heater will change).

A car is another example of an object. It has a lot of attributes such as fuel capacity, current speed, top speed, number of wheels, type of gearbox etc. There are also a lot of operations which you can perform on this object. For example: you can accelerate the car, apply brakes etc. The attributes of a car will have some values at any given instance of time. Once the car is in motion, you can say that at a particular time the speed of the car is 30 km/hr (thus current speed will be 30km/hr). Similarly, the color of the car is red or the car has four wheels. The values for the attributes at any given instant of time define the state of the object. There are two types of states an object can have: static and dynamic. Some attributes of the car will not change over a period of time. The number of wheels in the car is always going to be four (unless you are making a new prototype!). The color of the car would also remain the same for a long time. These attributes contribute to the static state of the car. The current speed of the car is a dynamic property which will change frequently depending on the actions performed upon the car. In OO terminology you will encounter the following terms frequently:

  • State
  • Behavior
  • Identity

Behavior of an object refers to the set of operations (or actions) that can be performed on an object.

Every object will have some attribute that can be used to uniquely identify the object. For example let’s take the example of a car as an object. All cars have color as an attribute. But can you distinguish two cars based on their colors? Definitely not. But you can distinguish two cars based on their registration number. Hence registration number is the attribute which can be used to uniquely identify a car. If you take a banking example then the account number is a unique way to identify an account (no two accounts can have the same account number).

An object will have two parts:

  1. Interface
  2. Implementation

In a car, the interface is the acceleration and braking actions which can be performed on the car (there are many more but lets just limit ourselves to these two actions). The driver is going to be the user of the car. When the driver presses the accelerator pedal, there are a lot of things that happen within the car which actually cause the rpm (rotations per minute of the wheel) to increase. Is the driver concerned about what actually happens within the engine? No. The driver just wants the car to accelerate on pressing the pedal and is least bothered about the underlying mechanisms used by the manufacturers to achieve this. He doesn’t care about how the engine is designed or as to how the piston is moving to achieve acceleration. All he knows (and wants to know generally) is that the car should accelerate when he presses the pedal. These internal mechanisms are called implementation details in OOP terminology. One of the central features of OOP is to separate the interface from the implementation. The person using an object should not know/worry about the implementation. This is what is termed encapsulation.

Hope it Helps you in understanding OOPs….

Happy Coding 🙂

August 23, 2012

Solution for Parsing an Excel file in C# and the cells seem to get cut off at 255 characters

Filed under: DotNet — tosaik @ 8:10 am
Tags: , , , , ,

Problem: An excel sheet containing say 10 rows and in couple of columns in couple of rows having data with more than 255 characters. When I try to upload this file in ASP.Net application using traditional OLEDB provider I cannot saw the whole data in particular cell means which is chopping out or we can say trimming to 255 characters when loaded in to my dataset object.

Solution: Having done sleepless nights I found some solutions to fix this issue… those are presented below


If your application is used only on one computer then you can directly go to the following registry settings and change the TypeGuessRows  value.


64 bit systems:


By setting this value to zero, the all lines of your spreadsheet are scanned for type guessing, rather than the default of 8. If any text fields longer than 255 chars are encountered, then those columns are deemed to be memo fields.

Note that you are still not 100% guaranteed to get the right data types, depending on your data.

Note also the HKLM scope of this key though – it will affect every OleDB Excel import by any process on that machine and this lead to degrade performance depending on the size of the data.


A second way to work around this problem (without modifying the registry) is to make sure that rows with fields, which have data 255 characters or greater, are present in the first 8 rows (default value of TypeGuessRows is 8) of the source data file.


This is the recommended solution by me as there is no need to change any registry or take care to have those lengthy data to be in first 8 rows. Instead we have a tool called NPOI which can be download from

Using this dll we can upload the spreadsheet without worrying of chopping your data and also it has many features like creating the spreadsheet on fly including charts, reports etc.., for more information you can find on this site

Anyway reading data using this NPOI is different from the traditional OLEDB provider. Please find the following method which with return a Data Table object by sending the File Path and the respective SheetName as input.

public static DataTable getExcelData(string FileName, string strSheetName)
        DataTable dt = new DataTable();
        HSSFWorkbook hssfworkbook;
        using (FileStream file = new FileStream(FileName, FileMode.Open, FileAccess.Read))
            hssfworkbook = new HSSFWorkbook(file);

        ISheet sheet = hssfworkbook.GetSheet(strSheetName);
        System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
        while (rows.MoveNext())
            IRow row = (HSSFRow)rows.Current;

            if (dt.Columns.Count == 0)
                for (int j = 0; j < row.LastCellNum; j++)


            DataRow dr = dt.NewRow();
            for (int i = 0; i < row.LastCellNum; i++)
                ICell cell = row.GetCell(i);

                if (cell == null)
                    dr[i] = null;
                    dr[i] = cell.ToString();

        return dt;

 May be I presented the solutions straight forward without more explanation or discussion but presently my motto is to provide you the reasonable and permanent solution for those who suffering with similar problem.

Hope this research and the code helps you a lot.. if so please drop a comment below which may be more encroached for me..


Happy Coding  🙂

July 31, 2012

Microsoft delivering Windows Phone Mango toolkit for Silverlight developers

Filed under: Mobile Apps — tosaik @ 6:23 am
Tags: ,

Great News !!!

Microsoft delivers Windows Phone Mango toolkit for Silverlight developers

Microsoft is continuing to inch toward the roll-out of Mango, the next version of its Windows Phone operating system. The company just made available to developers a new Silverlight toolkit for the Mango release.

With just a few days left before Windows Phone developers can submit their “Mango” applications for inclusion in the Windows Phone Marketplace, Microsoft is making a new toolkit for Silverlight coders available.

Microsoft made available for download the Silverlight for Windows Phone Toolkit add-on for the Windows Phone 7.1 SDK (software development kit) on August 17. The Mango 7.1 SDK is currently in beta, with a Release Candidate due in “late August,” according to the Softies.

In a new post on the Windows Phone developer blog, Microsoft officials said the toolkit will include user interface controls with components like toggle switches, page transitions, picker controls and more. Microsoft also has localized the toolkit into all the languages which will be supported by Mango.

Microsoft officials said recently that the Windows Phone Marketplace will be open for Mango application submissions on August 22. Earlier this week, Microsoft officials provided more guidance about how developers should think about transitioning their Windows Phone apps for Mango.

Microsoft and its OEM partners are expected to begin rolling out new Windows Phone 7.5 handsets preloaded with Mango (Windows Phone OS 7.1) this fall.

Mango adds a number of new features to the Windows Phone operating system, including third-party multitasking, Twitter integration, new Bing audio and visual search capabilities and more.


July 30, 2012

Explaining how we can open and close Files in C++.

Filed under: C++,OOPS Languages — tosaik @ 12:39 pm
Tags: , ,

Now we shall deal with file I/O and to access any device you have to make use of another header file: ‘fstream.h’. This header file has a number of classes already defined. To access a file you have to have a stream. We have already come across the classes istream, ostream and iostream. From these classes, 3 more classes are derived (they are ofstream, ifstream, and fstream) and these classes are specifically useful for streams used in ‘file’ operations. The hierarchy of classes will be as shown in the figure.










As can be seen, the ‘ifstream’, ‘ofstream’ and ‘fstream’ classes are derived from the ‘istream’, ‘ostream’ and ‘iostream’ classes. These are file streams that are derived from the general I/O streams that we have seen earlier.

ifstream in;             // file stream named ‘in’ created for handling input

ofstream out;         // file stream named ‘out’ created for handling output
fstream both;         // file stream named ‘both’- can handle both input and output

Opening File

Once you’ve created a stream, you can use the open ( ) function to associate it to a ‘file’. To associate the stream to a disk file, we should specify the name of the disk file. The open ( ) function is a member available in all the three classes. It can be used as follows: (“text.txt”) ;         // Opens a file called text.txt for output.

Note: When you say that a file is opened for output, it actually means that now you can write data to the file. When a file is opened for input (i.e. using ifstream), the data in the file can be displayed on the screen.

What if there already is a file called text.txt. When using the output stream (ofstream), the stream will create a new file text.txt. Whatever content was there in the original text.txt gets deleted and you can write new data to text.txt.

The 3 classes (ofstream, ifstream, fstream) have a constructor function that makes it easier to open a file. Example:

ofstream out(“text.txt”);

This creates an object out for output and opens the file text.txt in one single statement. Here we don’t make use of the open ( ) function.

Closing a File

 Anything that you open has to be closed. The member function for closing is close ( ). Since you do all I/O through the stream, you have to close the stream as follows:

stream-name.close( );

Actually you can link this back to the object and classes concept. ‘stream-name’ is an object and close is a member function of the ofstream class. Hence by saying

 stream-name.close( );

You’re actually invoking the member function close( ). A stream is associated to a device when using the open function. When the close ( ) function is used, the stream is disassociated from the device.

Happy Coding 🙂

June 20, 2012

Explaining briefly the working mechanism of virtual functions in C++

Filed under: C++,OOPS Languages — tosaik @ 10:45 am
Tags: , ,

A virtual function is a member function of a class, whose functionality can be over-ridden in its derived classes. It is one that is declared as virtual in the base class using the virtual keyword. The virtual nature is inherited in the subsequent derived classes and the virtual keyword need not be re-stated there. The whole function body can be replaced with a new set of implementation in the derived class.


Binding refers to the act of associating an object or a class with its member. If we can call a method fn() on an object o of a class c, we say that the object o is binded with the method fn(). This happens at compile time and is known as static or compile – time binding. The calls to the virtual member functions are resolved during run-time. This mechanism is known as dynamic binding. The most prominent reason why a virtual function will be used is to have a different functionality in the derived class. The difference between a non-virtual member function and a virtual member function is, the non-virtual member functions are resolved at compile time.

Working Process of Virtual Functions:

Whenever a program has a virtual function declared, a v – table is constructed for the class. The v-table consists of addresses to the virtual functions for classes that contain one or more virtual functions. The object of the class containing the virtual function contains a virtual pointer that points to the base address of the virtual table in memory. Whenever there is a virtual function call, the v-table is used to resolve to the function address. An object of the class that contains one or more virtual functions contains a virtual pointer called the vptr at the very beginning of the object in the memory. Hence the size of the object in this case increases by the size of the pointer. This vptr contains the base address of the virtual table in memory. Note that virtual tables are class specific, i.e., there is only one virtual table for a class irrespective of the number of virtual functions it contains. This virtual table in turn contains the base addresses of one or more virtual functions of the class. At the time when a virtual function is called on an object, the vptr of that object provides the base address of the virtual table for that class in memory. This table is used to resolve the function call as it contains the addresses of all the virtual functions of that class. This is how dynamic binding is resolved during a virtual function call.

The following code shows how we can write a virtual function in C++ and then use the same to achieve dynamic or runtime polymorphism.

#include <iostream.h>
class base
virtual void display()
class derived : public base
void display()

void main()

base *ptr = new derived();

In the above example, the pointer is of type base but it points to the derived class object. The method display() is virtual in nature. Hence in order to resolve the virtual method call, the context of the pointer is considered, i.e., the display method of the derived class is called and not that of the base. If the method was non virtual in nature, the display() method of the base class would have been called.

A constructor cannot be virtual because at the time when the constructor is invoked the virtual table would not be available in the memory. Hence we cannot have a virtual constructor.


Virtual methods should be used judiciously as they are slow due to the overhead involved in searching the virtual table. They also increase the size of an object of a class by the size of a pointer. The size of a pointer depends on the size of an integer. Note that in DOS based systems the size of a pointer is 2 bytes whereas in UNIX based systems it is 4 bytes.

Happy Coding 🙂

Short Description about Abstract Classes

Filed under: C++,OOPS Languages — tosaik @ 10:40 am
Tags: , ,

An abstract class is a class that is designed to be specifically used as a base class. An abstract class contains at least one pure virtual function. You declare a pure virtual function by using a pure specifier (= 0) in the declaration of a virtual member function in the class declaration.

The following is an example of an abstract class:

class vehicle{


virtual void speed() = 0;


Function vehicle::speed is a pure virtual function. A function declaration cannot have both a pure specifier and a definition. For example, the compiler will not allow the following:

struct A {

virtual void g() { } = 0;


You cannot use an abstract class as a parameter type, a function return type, or the type of an explicit conversion, nor can you declare an object of an abstract class. You can, however, declare pointers and references to an abstract class. The following example demonstrates this:

class A {

virtual void f() = 0;


class B :public A {

virtual void f() { }


// Error:

// Class A is an abstract class

// A g();

// Error:

// Class A is an abstract class

// void h(A);

A& i(A&);

int main() {

// Error:

// Class A is an abstract class

//   A a;

A* pa;

B b;

// Error:

// Class A is an abstract class

//   static_cast<A>(b);


Class A is an abstract class. The compiler would not allow the function declarations A g() or void h(A), declaration of object a, nor the static cast of b to type A.

Virtual member functions are inherited. A class derived from an abstract base class will also be abstract unless you override each pure virtual function in the derived class.

For example:

class AB {


virtual void f() = 0;


class D2 : public AB {

void g();


int main() {

D2 d;


The compiler will not allow the declaration of object d because D2 is an abstract class; it inherited the pure virtual function f()from AB. The compiler will allow the declaration of object d if you define function D2::g().

Note that you can derive an abstract class from a nonabstract class, and you can override a non-pure virtual function with a pure virtual function.

You can call member functions from a constructor or destructor of an abstract class. However, the results of calling (directly or indirectly) a pure virtual function from its constructor is undefined. The following example demonstrates this:

Class A {

A() {




virtual void direct() = 0;

virtual void indirect() { direct(); }


The default constructor of A calls the pure virtual function direct() both directly and indirectly (through indirect()).

The compiler issues a warning for the direct call to the pure virtual function, but not for the indirect call.

June 19, 2012

How Inheritance is importance in Object Oriented Programming?

Filed under: C++,DotNet,OOPS Languages — tosaik @ 5:41 pm
Tags: , , ,

One of the important features in the Object Oriented Programming is Reusability, as we said above that it is always good way to reuse the already existing functionality rather than trying to create the same one again and again. By reusing the properties not only saves the time and money but also increases the reliability.

An advantage of inheritance is that modules with sufficiently similar interfaces can share a lot of code, reducing the complexity of the program.

The Benefits of Inheritance

  • Subclasses provide specialized behaviors from the basis of common elements provided by the superclass. Through the use of inheritance, programmers can reuse the code in the superclass many times.
  • Programmers can implement superclasses called abstract classes that define “generic” behaviors. The abstract superclass defines and may partially implement the behavior but much of the class is undefined and unimplemented. Other programmers fill in the details with specialized subclasses.

Happy Coding 🙂

You are attempting to access powerpivot data that was added using a newer version of powerpivot

Filed under: PowerPivot — tosaik @ 5:33 pm

The Report which you are using is built on new power pivot version, for this reason reports are not working on old power pivot version and showing below error message.

The Report which you are using is built on new power pivot version, for this reason reports are not working on old power pivot version and showing below error message.

Resolution: Please install new version of power pivot (i.e. 11.0.2100.60) from below link.

Impact : If you are installed new power pivot version from above link existing reports which are built on old Power pivot will open with the below message in a dialogue box

Saying that “Do you want Upgrade the workbook”, if you click on OK the report will work fine.

« Previous PageNext Page »

Create a free website or blog at

%d bloggers like this: