Showing posts with label c-sharp. Show all posts
Showing posts with label c-sharp. Show all posts

Tuesday, June 11, 2013

Client Object Model vs Server Object Model in SharePoint 2010

Client Object Model 

Client object model is a new feature available in SharePoint 2010. .Client object model provides a  way to do the programming for a SharePoint site using scripting language such as Java Script .


In  Client object model an xml request will be sent  and then server will return JSON which is changed to appropriate object model. 

Mainly 2 assemblies to be referred while working with the Client object model.

Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.Client.Runtime.dll

Below is the code sample for a list object from SharePoint site using Client object model :
ClientContext context = new ClientContext("http://sp2010:2012");
 List list = context.Web.Lists.GetByTitle("Title");
context.Load(list);
context.ExecuteQuery();
So, what else a developer can do with Client object model. Client object model provide a way where you can access SharePoint data with scripting language such as Java Script.
You can write simple java script code to perform all those operation. You can use CAML query to access data from SharePoint site.


Using Client object model you can do below tasks:
Get list items, Add list items, Update list items and many more.

Client object model gives result in fast manner, but there is a limitation. The limitation is, we can not access Farm Object using Client object model.
For Client object model silverlight is also an option to program for a SharePoint site.

So if you want to access Farm object then use Server object model.


Server Object Model :



Server object model contains following classes : SPFarm, SPServer, SPSite, SPSiteCollection etc.

Below is the code Sample for Server Object Model:
This code is to get the list items from a SharePoint site:

          using (SPSite oSite = new SPSite(@"http://sp2010:33051"))
            {
                using (SPWeb oWeb = oSite.RootWeb)
                {
                    SPList oList = oWeb.Lists["List1"];  
                    Console.WriteLine("Items in: " + oList);
                    foreach (SPListItem oItem in oList.Items)
                    {
                        string firstname = oItem["Fname"].ToString();
                        Console.WriteLine(firstname);
                    }
                 }
            }

If you want more on Client object model or Server object model then please comment your query. Your comment will be highly appreciated.

Wednesday, October 24, 2012

Sharepoint 2013 The context has expired and can no longer be used


I came across this odd error a couple of times in the past few weeks, so I wrote a quick guide that might help you get rid of it.
If you see this error after opening your SharePoint 2013 site, there is a lack of synchronization between Date and Time settings in your SharePoint 2013 Server and your SharePoint web application.
Sorry, something went wrong. The context has expired and can no longer be used. (Exception from HRESULT: 0×80090317)

Here is how you fix it!




  • Open Central Administration -> Application Management.
  • Locate the relevant Web Application and click on 
  • Web Application General Setting window will open up, notice that the Default Time Zone is missing.

Open Date and Time options on your server and check which time zone is configured. Configure the same time zone in Web Application General Setting.


Perform IIS Reset and open your SharePoint 2013 site again.


Hooray! SharePoint site works again!

Ref Link : http://blog.cloudshare.com/2012/10/22/how-to-fix-sharepoint-2013-web-application-error-the-context-has-expired-and-can-no-longer-be-used/#more-3508

Wednesday, September 19, 2012

C sharp basic interview questions and answers for freshers

Can an Interface contain fields?
No, an Interface cannot contain fields.

Can you create an instance of an interface?
No, you cannot create an instance of an interface.

1.Does C# support multiple-inheritance?
No. But you can use Interfaces.

2.Where is a protected class-level variable available?
It is available to any sub-class derived from base class

3.Are private class-level variables inherited?
Yes, but they are not accessible.

How do you create empty strings in C#?
Using string.empty as shown in the example below.
string EmptyString = string.empty;

4.Describe the accessibility modifier “protected internal”.
It is available to classes that are within the same assembly and derived from the specified base class.

6.Which class is at the top of .NET class hierarchy?
System.Object.

7.What does the term immutable mean?
The data value may not be changed.
Note: The variable value may be changed, but the original immutable data value was discarded and a new data value was created in memory.

8.What’s the difference between System.String and System.Text.StringBuilder classes?
System.String is immutable.
System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.

9.What’s the advantage of using System.Text.StringBuilder over System.String?

StringBuilder is more efficient in cases where there is a large amount of string manipulation. Strings are immutable, so each time a string is changed, a new instance in memory is created.

10.Can you store multiple data types in System.Array?
No.

11.What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?
The Clone() method returns a new array (a shallow copy) object containing all the elements in the original array. The CopyTo() method copies the elements into another existing array. Both perform a shallow copy. A shallow copy means the contents (each array element) contains references to the same object as the elements in the original array. A deep copy (which neither of these methods performs) would create a new instance of each element's object, resulting in a different, yet identacle object.

12.How can you sort the elements of the array in descending order?
By calling Sort() and then Reverse() methods.

13.What’s the .NET collection class that allows an element to be accessed using a unique key?
HashTable.

14.What class is underneath the SortedList class?
A sorted HashTable.

15.Will the finally block get executed if an exception has not occurred?
Yes.

16.What’s the C# syntax to catch any possible exception?
A catch block that catches the exception of type System.Exception. You can also omit the parameter data type in this case and just write catch {}.

17.Can multiple catch blocks be executed for a single try statement?
No. Once the proper catch block processed, control is transferred to the finally block .

18.Explain the three services model commonly know as a three-tier application?
Presentation (UI), Business (logic and underlying code) and Data (from storage or other sources)



1. How many types of JIT compilers are available?
There are Two types of JIT compilers.
standard JIT compiler.
EconoJIT compiler.

2.What are the different types of assemblies – name them?
Private
Public/Shared
Satellite assembly

3.What is GAC? What are the steps to be taken to pick up the latest version from GAC?
This Global Assembly Cache(GAC) stores .NET assemblies to be shared by several applications on that computer.publisher policy file is the configuration file to redirect to different version
1. Create the publisher Policy assembly using the assembly linker
2. Add the publisher policy assembly to the GAC using GACutil tool
Gacutil /i
3. During runtime CLR is looking into the publisher policy file and redirect the application to bind with new version assembly as specified inside the publisher policy.


4.How do we use different versions of private assemblies in same application without re-build?
In Asseblyinfo file need specify assembly version.
assembly: AssemblyVersion

5.Different methods of using a legacy COM component in .NET framework?
1. TLBIMP to create an Assembly from a COM component
2. Reference a COM component directly from .NET Editor

6.How do you implement SSL?
1. create certificate request
[
=>Right click on the website (VD)
=>Click Directory Security Tab and click Server Certificate
=> Type name of certificate , Organization name , server name
location info,
=> Type the path need to save certificate information Submit certificate request.
]

7.What is ref parameter? What is out parameter?
Ref Parameter: Used to pass a parameter as a reference so that the function called will set the value. This could be used to return more than 1 value by a function.
e.g.
public int AddMuliply( int a , int b, ref int c)
{
c = a*b;
return ( a+b);
}
The above function, returns the addition of two numbers as well as computes the multiplication result and passes to the calling function.
Out Parameter: Used to pass values from the aspx Code-behind to the aspx page.
The difference is that for a ref parameter, you have to assign a value before you call the function, while for OUT parameter, you dont have to assign a value, the calling function assumes that the called function would assign some value.

A ref parameter must first be initialized before being passed from the calling function to the called function. but a out parameter need not be initialized, we can pass it directly when we pass a parameter as ref to a method, the method refers to the same variable and changes made will affect the actual variable.
even the variable passed as out parameter is same as ref parameter, but implementation in c# is different, Arguement passed as ref parameter must be initialized before it is passed to the method. But in case of out parameter it is not necessary. But after a call to a method as out parameter it is necessary to initialize.
When to use out and ref parameter, out parameter is used when we want to return more than one value from a method. Ref parameter can be used as both input and o/p parameter out parameter can be used as only output parameter

8.What is boxing? What is the benefits and disadvantages?
Boxing is converting a value-type to reference type. An example is converting an integer value to an object value.

Ex:
int intValue = 10;
object obj = (object)intValue;

This is used if you want to pass variables of object types to certain functions or methods you have created. Commonly used in events for example (Object sender...).

9.Why multiple Inheritance is not possible in C#?
Multple inheritance is coneceptually wrong. It shouldn't be allowed in any language. Inheritance is the strongest relationship that can be expressed in OO languages.
It's used to express IS-A relationship. Aggregation is used to express IS CONSTRUCTED IN TERMS OF. If you're using multiple inheritance in C++ then you're design is wrong and you probably want to use aggregation. On the other hand it's plausible to want to use multiple interfaces. For instance you might have a class wheel and a class engine. You could say that your class car inherits from wheel and from engine but that's wrong. In fact car aggregates wheel and engine because it is built in terms of those classes. If wheel is an interface and engine is an interface then car must inherit both of these interfaces since it must implement the functionaity of wheel and engine .On this basis we can see that multiple inheritance for classes should not be allowed because it promotes mis-use of the strong IS-A relationship. C# enforces the correct concepts whilst C++ allows mis-use. multiple interface inheritance is permissible and C# allows this. It's all to do with properly understanding OO concepts.

Absolute Multiple Inheritance is not possible in c# but partially it supports multiple inheritance by the use of Interfaces. As interfaces force a class to implement same type of behaviour (as defined in interface) which classes implements that interface

What is a Web Application - Interview Questions

A web application is any application that uses a web browser as a client. The application can be as simple as a message board or a guest sign-in book on a website, or as complex as a word processor or a spreadsheet

A web application is a dynamic extension of a web or application server. There are two types of web applications:

Presentation-oriented: Web application

A presentation-oriented web application generates interactive web pages containing various types of markup language (HTML, XML, and so on) and dynamic content in response to requests.

Service-oriented: Web application

A service-oriented web application implements the endpoint of a web service. Presentation-oriented applications are often clients of service-oriented web applications.

Web Development Company

What is ASP.NET - Asp.net Interview Questions


  • ASP.NET is a Web application framework marketed by Microsoft that can be used to build dynamic Web sites, Web applications, and XML Web services.
  • It is part of Microsoft's .NET platform and is the successor to Microsoft's Active Server Pages (ASP) technology.
  • Applications developed using ASP.NET must be hosted on an Internet Information Services (IIS) server.

How ASP .NET different from ASP - Asp.net Interview Questions

Scripting is separated from the HTML, Code is compiled as a DLL, these DLLs can be executed on the server.

Process Isolation
ASP is run under the inetinfo.exe(IIS) process space and hence susceptible to application crashes as a result the IIS needs to be stopped or restarted. ASP is related to the process isolation setting in IIS.

But, ASP.Net The ASP.NET worker process is a distinct worker process, aspnet_wp.exe, separate from inetinfo.exe ( IIS process), and the process model in ASP.NET is unrelated to process isolation settings in IIS.

Multi Language Support in WebPage
In ASP only two languages were available for scripting VBScript and Jscript/Javascript.

But in ASP.NET We are no longer constrained to the two scripting languages available in traditional ASP: Any fully compliant .NET language can now be used with ASP.NET, including C# and VB.NET.

Note :- (C# and VB.Net are both server Side languages.) 

Interpretation Vs Compilation
In ASP, ASP engine executes server-side code, which is always through an interpreter (JScript or VBScript). When a traditional ASP page is requested, the text of that page is parsed linearly. All content that is not server-side script is rendered as is back to the response. All server-side script in the page is first run through the appropriate interpreter (JScript or VBScript), the output of which is then rendered back to the response. This architecture affects the efficiency of page rendering in several ways. First, interpreting the server-side script on the fly.As a side effect, one common optimization for ASP applications is to move a lot of server-side script into precompiled COM components to improve response times. A second efficiency concern is that intermingling server-side evaluation blocks with static HTML is less efficient than evaluating a single server-side script block, because the interpreter has to be invoked over and over again. Thus, to improve efficiency of rendering, many ASP developers resort to large blocks of server-side script, replacing static HTML elements with Response.Write() invocations instead. Finally, this ASP model actually allows different blocks of script within a page to be written in different script languages. While this may be appealing in some ways, it also degrades performance by requiring that a particular page load both scripting engines to process a request, which takes more time and memory than using just one language.

But in ASP.NET, In contrast, ASP.NET pages are always compiled into .NET classes housed within assemblies. This class includes all of the server-side code and the static HTML, so once a page is accessed for the first time (or any page within a particular directory is accessed), subsequent rendering of that page is serviced by executing compiled code. This eliminates all the inefficiencies of the scripting model of traditional ASP. There is no longer any performance difference between compiled components and server-side code embedded within a page they are now both compiled components. There is also no performance difference between interspersing server-side code blocks among static HTML elements, and writing large blocks of server-side code and using Response.Write() for static HTML content. Also, because the .aspx file is parsed into a single code file and compiled, it is not possible to use multiple server-side languages within a single .aspx file.

What are the advantage of Asp.net

ASP.NET provides the following advantages:
  • Enables you to access information from data sources, such as back-end databases and text files that are stored on a Web server.
  • Provides enriched tool support in the form of Visual Studio .NET integrated development environment (VS .NET IDE).
  • Enables you to develop your application in any .NET language.
  • Enables you to build user interfaces that separate application logic from presentation content.
  • Enables you to manage Web applications by storing the configuration information in an XML file.
  • Helps improve developer productivity and provides facilities for improving the performance, reliability, and scalability of Web applications.

Tuesday, September 18, 2012

What is the main difference between an ASP.NET Web application and a traditional Windows application

ASP.NET Web applications runs under common language runtime using managed code where as Unmanaged Windows application runs under Windows using unmanaged code.

List the four major differences between Web and Windows applications.

  • Web forms cannot use the standard Windows controls. Instead, they use server controls, HTML controls, user controls, or custom controls created specially for Web forms.
  • Web applications are displayed in a browser. Windows applications display their own windows and have more control over how those windows are displayed.
  • Web forms are instantiated on the server, sent to the browser, and destroyed immediately. Windows forms are instantiated, exist for as long as needed, and are destroyed.
  • Web applications run on a server and are displayed remotely on clients. Windows applications run on the same machine they are displayed on.

Explain the life cycle of an ASP .NET page

ASP.NET 2.0 Page Life Cycle - The lifetime of an ASP.NET page is filled with events. A .NET technical interview might begin with this question. A series of processing steps takes place during this page life cycle. Following tasks are performed:
  • Initialization
  • Instantiation of controls
  • Restoration & Maintainance of State
  • Running Event Handlers
  • Rendering of data to the browser
The life cycle may be broken down into Stages and Events. The stages reflect the broad spectrum of tasks performed. The following stages take place
  1. Page Request - This is the first stage, before the page life cycle starts. Whenever a page is requested, ASP.NET detects whether the page is to be requested, parsed and compiled or whether the page can be cached from the system.
  2. Start - In this stage, properties such as Request and Response are set. Its also determined at this stage whether the request is a new request or old, and thus it sets the IsPostBack property in the Start stage of the page life cycle.
  3. Page Initialization - Each control of the page is assigned a unique identification ID. If there are themes, they are applied. Note that during the Page Initialization stage, neither postback data is loaded, nor any viewstate data is retrieved.
  4. Load - If current request is a postback, then control values are retrieved from their viewstate.
  5. Validation - The validate method of the validation controls is invoked. This sets the IsValid property of the validation control.
  6. PostBack Event Handling - Event handlers are invoked, in case the request is a postback.
  7. Rendering - Viewstate for the page is saved. Then render method for each control is called. A textwriter writes the output of the rendering stage to the output stream of the page's Response property.
  8. Unload - This is the last stage in the page life cycle stages. It is invoked when the page is completely rendered. Page properties like Respone and Request are unloaded.

what is application state in asp.net

ASP.NET allows you to save values using application state, a global storage mechanism that is accessible from all pages in the Web application. Application state is stored in the Application key/value dictionary. Once you add your application-specific information to application state, the server manages it, and it is never exposed to the client. Application state is a great place to store information that is not user-specific. By storing it in the application state, all pages can access data from a single location in memory, rather than keeping separate copies of the data. Data stored in the Application object is not permanent and is lost any time the application is restarted.
ASP.NET provides three events that enable you to initialize Application variables (free resources when the application shuts down) and respond to Application errors:

a.Application_Start: Raised when the application starts. This is the perfect place to initialize Application variables.

b.Application_End: Raised when an application shuts down. Use this to free application resources and perform logging.

c.Application_Error: Raised when an unhandled error occurs. Use this to perform error logging.

Example :

// This sets the value of the Application Variable



Application["Name"] = txtName.Text; 

Response.Redirect("WebForm5.aspx"); 



// This is how we retrieve the value of the Application Variable



if( Application["Name"] != null ) 

    Label3.Text = Application["Name"].ToString();

What is session state in asp.net

A session is defined as the period of time that a unique user interacts with a Web application.
Session state is a collection of objects, tied to a session are stored on a server.
Session State information is available to all pages opened by a user during a single visit

ASP.NET allows you to save values using session state, a storage mechanism that is accessible from all pages requested by a single Web browser session. Therefore, you can use session state to store user-specific information. Session state is similar to application state, except that it is scoped to the current browser session. If different users are using your application, each user session has a different session state. In addition, if a user leaves your application and then returns later after the session timeout period, session state information is lost and a new session is created for the user. Session state is stored in the Session key/value dictionary.

You can use session state to accomplish the following tasks:
i.Uniquely identify browser or client-device requests and map them to individual session instances on the server. This allows you to track which pages a user saw on your site during a specific visit.

ii.Store session-specific data on the server for use across multiple browser or client-device requests during the same session. This is perfect for storing shopping cart information.

iii.Raise appropriate session management events. In addition, you can write application code leveraging these events.

ASP.NET session state supports several different storage options for session data:

a.InProc Stores session state in memory on the Web server. This is the default, and it offers much better performance than using the ASP.NET state service or storing state information in a database server. InProc is fine for simple applications, but robust applications that use multiple Web servers or must persist session data between application restarts should use State Server or SQLServer.

b.StateServer Stores session state in a service called the ASP.NET State Service. This ensures that session state is preserved if the Web application is restarted and also makes session state available to multiple Web servers in a Web farm. ASP.NET State Service is included with any computer set up to run ASP.NET Web applications; however, the service is set up to start manually by default. Therefore, when configuring the ASP.NET State Service, you must set the startup type to Automatic.

c.SQLServer Stores session state in a SQL Server database. This ensures that session state is preserved if the Web application is restarted and also makes session state available to multiple Web servers in a Web farm. On the same hardware, the ASP.NET State Service outperforms SQLServer. However, a SQL Server database offers more robust data integrity and reporting capabilities.

d.Custom Enables you to specify a custom storage provider. You also need to implement the custom storage provider.

e.Off Disables session state. You should disable session state if you are not using it to improve performance.

Example:Sessions are created as soon as the first response is being sent from the client to the server, and session ends when the user closes his browser window or some abnormal operation takes place. Here is how you can use session variables fortransferring values. Below you can see a Session is created for the user and "Name" is the key, also known as the Session key, which is assigned the TextBox value.


// Session Created



Session["Name"] = txtName.Text; 

Response.Redirect("WebForm5.aspx");



// The code below shows how to get the session value.



// This code must be placed in other page.



if(Session["Name"] != null) 

    Label3.Text = Session["Name"].ToString();

What is view state

ViewState: Its nothing but it's a hidden data which is kept by asp.net pages in "_VIEWSTATE" as hidden form field. They track the changes to a web site during post backs.
The ViewState of a page can be seen if you view the source code of the running page(Right Click --> View Source). It will be listed under the following tags:
< input id="__VIEWSTATE" name="__VIEWSTATE" type="hidden" value=""  >
Having a large ViewState will cause a page to download slowly from the users side.

source view

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE” value="/wEPDwUKMTIxNDIyOTM0Mg9kFgICAw9kFgICAQ8PFgIeBFRleHQFEzQvNS8yMDA2IDE6Mzc6MTEgUE1kZGROWHn/rt75XF/pMGnqjqHlH66cdw==" />

Encrypting of the View State: You can enable view state encryption to make it more difficult for attackers and malicious users to directly read view state information. Though this adds processing overhead to the Web server, it supports in storing confidential information in view state. To configure view state encryption for an application does the following:

<Configuration>
   <system.web>
                  <pages viewStateEncryptionMode="Always"/>
  </system.web>
</configuration>

Alternatively, you can enable view state encryption for a specific page by setting the value in the page directive, as the following sample demonstrates:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" ViewStateEncryptionMode="Always"%>

View State is enabled by default, but if you can disable it by setting the EnableViewState property for each web control to false. This reduces the server processing time and decreases page size.