Translate

Friday, August 31, 2012

Using Overriding and Hiding Methods in C#


Overriding in C#


Extend or replace functionality in the base class
It is required to provide an implementation that has the same meaning as the original method, but has an implementation that is specific to the class. Virtual methods typically provide a default implementation that
inheriting classes are expected to replace with their own code.
To override a method in a subclass, you use the override keyword, as the following
code example shows
public Class Employee
{
protected int EmployeeNumber;
protected string EmployeeFirstName;
protected string EmployeeLastname;
protected float Salary;
Protected virtual void WorkAssigned()
{
}
}

//Program Manager class inheriting from  Employee class
Public Class TechnicalManager:Employee
{
Protected  Override void WorkAssigned()
{
}
}


Hiding Methods in C#
You can define methods in an inherited class that have the same name as methods
in a base class, even if they are not marked as virtual, abstract, or override.
However, this means that there is no relationship between your method and the
original method, and new method hides the original method.

Code
Public Class Employee
{
protected void  ActOn()
{
...
}
}
class Manager : Employee
{
public new void  ActOn()
{
// Hiding he ActOn method in the base class
//Code goes here
}

}

Inheriting from Classes and Implementing Interfaces

What is Inheritance or How to define Inheritance in C#


Inheritance is the most feature in the object oriented programming.
Inheritance helps not do the repetition of code the same code in the multiple places when dealing with
different classes  which have several features in common and are related to each other. Even they are
different subclasses of the same type, each with its own distinguishing feature


Declared and Define Inherited Class
Parent/Base Class
public Class Employee
{
protected int EmployeeNumber;
protected string EmployeeFirstName;
protected string EmployeeLastname;
protected float Salary;
Protected void WorkAssigned()
{
}

}

//Program Manager class inheriting from  Employee class
Public Class TechnicalManager:Employee
{
Public void ProgramManagerWorkAssigned()
{
}
}

//Program Technical Manager class inheriting from  Employee class
Public Class TechnicalManager:Employee
{
Public void TechnicalManagerWorkAssigned()
{
}
}


example, Program Manager and  Technical Manager ,Engineer are all employees of a Software Company .
When we are writing an application to simulate the Employee Management System, how would you specify that
Program Manager and Technical Manager and Engineer have several features that are the same, but also
other features that are different? For example, they all have an employee reference  employee number and a name and so on, also each one has different responsibilities. When we want to define class of Program Manager and Technical Manager and Engineer each has to be inheriting the employee. So we don’t need to define the common features in all the classes.

In C# inheritance is implemented by using “:” 

Thursday, August 30, 2012

How to Modify Navigation Settings in SharePoint

How to Modify Navigation Settings in SharePoint


It is sometimes it is required to hide/show the navigation of site created in the SharePoint
Sharepoint has a provision to add/remove /hide any links which is displayed in the SharePoint.

Steps

1.     Click on Site Actions èSite Settings. From theèLook and Feel section,
Choose Navigation.
 In the Current Navigation section,
2.     choose the option Display the same navigation items as the parent site and select the Show Pages checkbox:


How to Create Publishing site in SharePoint 2010

How to Create Publishing site in SharePoint 2010

To a new publishing site, publishing site is most important site template used in most of the orgainizations and it gives very good the content management site where the administrators are required to publish the content frequently.This can be done by creating content pages in the sharepoint.

Steps

1.     Go to Central Administration and click on the link for Create Site Collections.

2.     Ensure that the web application is selected correctly.


3. In the Template Selection section, choose the Publishing tab and select the
Publishing Portal template, as shown in the following screenshot:









4. Provide the Primary and Seconday Site Collection Administrator.
5. click OK.
6.Publishing site is created sucessfully.



Using Decision Statements in C# ternary operator If Else

Using Decision Statements in C#

Using the ?: Operator or ternary operator and If Else

C# performs the statements in a program in a sequential manner. However, you frequently need to specify that alternative statements should run depending on the value of an expression or a Boolean condition. To achieve this ,C# provides conditional decision statements. Explain how to use the if else statement.

1.     Using If Else
2.     Using ?: operator.
3.     Using  switch statement


If else
1.
If ([Condition]) //Code to Execute

2
.If ([Condition])
{
//If condition is true
//Code to Execute
}

3.
.If ([Condition1] && [Condition2])
{
//If condition is true
//Code to Execute
}

4.
.If ([Condition1] || [Condition2])
{
//If condition is true
//Code to Execute
}

if statements are very useful when you want to execute a code statement based on a condition. The basic syntax for a one-way if statement is shown in the following code example.

if ([condition]) [code to execute]

if the expression [condition] evaluates to a Boolean true value, [codeto execute] is executed. Notice that the condition must be enclosed in parentheses.You can execute more than one code statement. To do this, you delimit the code to run by using braces. This extends the syntax as the following code example shows.
if ([condition])
{
[code to execute if condition is true]

}
If(a>50)
{
C=a+b;
}

If Else statement
Provides additional code block to execute if [Condition] is evaluates to boolean false

If([Condition])
{
//Execute code
}
Else
{
//Else code to execute
}

Using the ?: Operator or ternary operator
As an alternative to using the if else statements, in some simple cases, you can use
the “?: “ ternary operator.The basic syntax to use the ?: operator is shown in the following code example.

Type result = [condition] ? [true expression] : [false expression]

If the expression [condition] evaluates to true, [true expression] is executed, but if the [condition] evaluates to false, [false expression] is executed.The following code example shows an example of using the ?: operator to check the value of a string, and then return a response.
string penColor = "green";
string response = (penColor == "red") ? "You have a red pen" :"You do not have a red pen";

Wednesday, August 29, 2012

Variable Scope in C#

Variable Scope in C#




Variables can have one of the following levels of scope:
• Block
• Procedure
• Class
• Namespace

Block
Code:
if (sum> 100)
{
int a= sum1+sum2;
}
Here the variable a is defined inside the Block {} and it scope is inside {} and cannot access the “a” outside of the block ,if try to access will give error.





Procedure Scope

code
Internal string  GetConnection()
{
String message=”Hello Procedure Scope”;
Response.Write(message);
}
In this sample message is declared and can be used in the method GetConnection()

Class Scope

Code:
Public static class Sample{
private string myMsg;
void SetMessage ()
{
myMsg = "Hello World!";
}
void ShowMessage ()
{
MessageBox.Show(myMsg);
}
}

In this sample “myMsg” is declared inside the Sample and used in two procedures

Assigning a Value to a Variable in C#

Assigning a Value to a Variable in C#


The assignment operator (=) assigns a value to a variable. The syntax of a variable assignment is shown in the following code.
VaraibleName=AssignedValue;

String helloAssignment=”I am from assignment”;

Declaring and Assigning Variables in C#

Declaring and Assigning Variables


When we need to use a variable we must need to declare by naming the variable which is known as identifier and its data type. To use some value in the variable we need to assigned the value.

Identifier
An identifier must start with a letter or an underscore, it can only contain letters, digits, and underscore characters.

Int a ;


C# Data Types or Data Types in C#

C# Data Types or what are Data Types in C#


A variable holds data that has a specified type. When we declare a variable to store data in an application, we are required to choose an appropriate data type for that data to hold.
It is known that C# is a type-safe language, which means that the compiler guarantees that values that are stored in variables are always of the appropriate type.

Frequently Used Data Types
The following table shows the frequently used data types in C#, and their characteristics.

Type
Size
Range
Description
Long
8
–2,147,483,648 to 2,147,483,647
Number with big range
Int
4
–9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
Whole Number
Float
4
+/–3.4 × 10^38
Float
Double
8
+/–1.7 × 10^308
Double
precision
(more
accurate)
floatingpoint
numbers
Decimal
16
28 significant figures
Decimal values
String
2 per character
There is no limit
List of characters
DateTime
8
0:00:00 on 01/01/0001 to 23:59:59 on
12/31/9999
Date and time

Variables in C#

Variables in C#


Variables stores values required by application in temporary memory locations, a variable represents a named location in memory for a piece of data. An application can access a piece of data by using the variable it has been assigned to variables store values that an application can change while it is running. Sometimes it is required to store values temporarily when we perform calculations or pass data between the user, an application, or a database.
A variable has the following six facets:
1.Name. Unique identifier that refers to the variable in code.
2. Address. Memory location of the variable.
3. Data type. Type and size of data that the variable can store.
4. Value. Value at the address of the variable.
5. Scope. Defined areas of code that can access and use the variable.

Sunday, August 26, 2012

SharePoint 2010 difference between Sever side object model and Client object model

SharePoint 2010 difference between Sever side object model and Client object model or Comparison between Server side object and client side object model

S.No.
Sever side object model
Client object model
1.
SharePoint installation is required
SharePoint installation is not required
2.
It works with strongly with server objects
Sharepoint 2010 has provided client objects
3.
The object needs to created and access in the site collection
It can be used in .Net applications like console or any application where if it is required to item update/delete/add
4.
using Microsoft.SharePoint
It can be used
Microsoft.SharePoint.Client.Runtime.dll
Microsoft.SharePoint.Client
Silverlight.Runtime.dll

5.
SPContext
SPSite
SPWeb
SPList
SPListItem
SPField
ClientContext
Site
Web
List
ListItem
Field

SharePoint Cloud Computing Book

SharePoint Cloud Computing Book

Sharepoint Cloud Computing Book This is one of the good book
"Microsoft Press - SharePoint 2010 Deploying Cloud-Based Solutions"
http://www.amazon.com/Microsoft-SharePoint-2010-Cloud-Based-Organizations/dp/073566210X

Adding file attachment in custom list programmatically

Adding file attachment in custom list programmatically


Code:

SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPSite mySite = new SPSite(“Site Url”); //Mentioned site url
                   SPWeb spweb = mySite.OpenWeb();

                    SPList list = spweb.Lists[“HR Policies”];
                    int ID = Convert.ToInt32(this.Page.Request.QueryString["ItemID"].ToString());
                 SPListItem spNewItem = myList.Items.Add();
                    spWeb.AllowUnsafeUpdates = true;
                    string fileName1 = System.IO.Path.GetFileName(“file Name”);//Mention File name
                    if (fileName1 != "")
                    {
                        Stream fStream = firstinputFile.PostedFile.InputStream;
                        byte[] contents = new byte[fStream.Length];
                        fStream.Read(contents, 0, (int)fStream.Length);
                        fStream.Close();
                        fStream.Dispose();
                        SPAttachmentCollection attachments = myNewItem.Attachments;
                        fileName1 = Path.GetFileName(firstinputFile.PostedFile.FileName);
                        attachments.Add(fileName1, contents);
                        spNewItem.Update();
               }
});


Using RunWithElevatedPrivileges or SPSecurity.RunWithElevatedPrivileges

Using RunWithElevatedPrivileges or SPSecurity.RunWithElevatedPrivileges


"RunWithElevatedPrivileges" method accepts a delegate code which wants to run with administrator’s privileges, actually the code runs under the application pool identity, which is mainly site collection administrator.
The namespace SPSecurity  is required for  RunWithElevatedPrivileges
Sample code shows the item updated code which runs in the SPSecurity.RunWithElevatedPrivileges
Code:
SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                SPSite mySite = new SPSite(“site url”);//mention site url
                 mySite.AllowUnsafeUpdates = true;
                 SPWeb spweb = mySite.OpenWeb();
                 spweb.AllowUnsafeUpdates = true;
                 SPList myList = spweb.Lists[“Demo List”];
                 SPListItem spNewItem = myList.Items.Add();
                 spNewItem["Title"] = “Test Title”;
                 spNewItem.Update();
});

Friday, August 24, 2012

Hardware and Software Requirements for SharePoint 15 or SharePoint 2013

Hardware and Software Requirements for SharePoint 15 or SharePoint 2013


The following requirements is for Web & Application Servers with single server farm
Hardware Requirement

Hardware Requirement
S.No.
Hardware Item
Requirement
1.
Processor
64 bit
2. 
Ram
8 GB
3.
Hard Disk
80 GB


Software Requirements
S.No.
Software Item
Requirement
1.
Windows
Windows Server 2008 R2
2.
SQL Server
Microsoft SQL Server 2008 R2 with Service Pack 1(64 bit)
3.
Web Server
IIS
4.
Sharepoint
Sharepoint 15
5.
.Net Framework
.Net Framework version 4.0
6.
Identity Foundation
Windows Identity foundation WIF 1.0 and 1.1
7.
Updates & other
.NET 4 DGR Update KB 2468871,
Information Protection & Control Client (MSIPC), Open Data Library (ODataLib)


8.
Windows PowerShell
Windows PowerShell 3.0