Thursday, March 29, 2012

WSS Interview Quetions

SP Object model
The following diagram shows the SharePoint Foundation server architecture in relation to the collections and objects of the Microsoft.SharePoint.Administration namespace.

1.       The SPFarm object is the highest object within the SharePoint Foundation object model hierarchy. The Servers property gets a collection representing all the servers in the deployment, and the Services property gets a collection representing all the services.
2.       Each SPServer object represents a physical server computer. The ServiceInstances property provides access to the set of individual service instances that run on the individual computer.
3.       Each SPService object represents a logical service installed in the server farm. Derived types of the SPService class include, for example, objects for Windows services, such as the timer service, search, the database service, etc. and also objects for Web services, such as the basic content publishing Web service which supports the Web applications.
4.       An SPWebService object provides access to configuration settings for a specific logical service or application. The WebApplications property gets the collection of Web applications that run the service.
5.       If the service implements the Service Application Framework of SharePoint Foundation, then it can be split into multiple configured farm-scoped instantiations (CFSIs). Each of these provides the functionality of the service but each has its own individual permission and provisioning settings.
6.       Each instance of a service, or a CFSI, that is running on a specific server is represented by an SPServiceInstance object.
7.       An SPDatabaseServiceInstance object represents a single instance of a database service running on the database server computer. The SPDatabaseServiceInstance class derives from the SPServiceInstance class and thus inherits the Service property, which provides access to the service or application that the instance implements. The Databases property gets the collection of content databases used in the service.
8.       Each SPWebApplication object represents a Web application hosted in an Internet Information Services (IIS) Web site. The SPWebApplication object provides access to credentials and other farm-wide application settings. The Sites property gets the collection of site collections within the Web application, and the ContentDatabases property gets the collection of content databases used in the Web application.
9.       An SPContentDatabase object inherits from the SPDatabase class and represents a database that contains user data for a Web application. The Sites property gets the collection of site collections for which the content database stores data, and the WebApplication property gets the parent Web application.
10.    An SPSiteCollection object represents the collection of site collections within the Web application.


The following diagram shows the SharePoint Foundation site architecture in relation to the collections and objects of the Microsoft.SharePoint namespace.
1.       Each SPSiteobject, despite its singular name, represents a set of logically related SPWeb objects (see below). Such a set is commonly called a "site collection," but SPSite is not a standard Microsoft .NET collection class, in contrast to SPWebCollection. Rather, it has members that can be used to manage the site collection. The AllWebs property provides access to the SPWebCollection object that represents the collection of all Web sites within the site collection, including the top-level site. The SPSite.OpenWebmethod of the SPSite class returns a specific Web site.
2.       Each site collection includes any number of SPWeb objects, and each object has members that can be used to manage a site, including its template and theme, as well as to access files and folders on the site. The Webs property returns an SPWebCollection object that represents all the subsites of a specified site, and the Lists property returns an SPListCollection object that represents all the lists in the site.
3.       Each SPList object has members that are used to manage the list or access items in the list. The GetItems method can be used to perform queries that return specific items. The Fields property returns an SPFieldCollection object that represents all the fields, or columns, in the list, and the Items property returns an SPListItemCollection object that represents all the items, or rows, in the list.
4.       Each SPField object has members that contain settings for the field.
5.       Each SPListItem object represents a single row in the list.


What is the difference between list and liberary.
1. List attachement field size is much low as compare to document liberary
2. List does not provide the checkin and checkout functionality while document liberary does.
3. In List we can not create the folder while in document liberary we can create the folders
4. List is specialized to contain the tabuler formate of data like in sql records while document liberary design keeping in mind to store the documents picure and videos.


Introduction 

Hi Friends, below is quick start FAQ for people who are new to share point. We will warm up some theory in the first two articles and then do some practical on the same lines. I have made a 10 part series for share point and I hope you will enjoy it. This is the first part from the series. Get warmed with the theory first and then rest of SharePoint is a breeeeeze. This section covers sharepoint basics and the walks through how share point works with ASP.NET.

What is SharePoint? 

Share point helps team members to connect and exchange information in a collaborative manner. It helps to centralize enterprise information for efficient functioning. For instance below is how a normal organization works. Files and documents scattered in individual PC and data is transported according to custom protocols. The communication protocol for sending these data is also person dependent. Some body would use a email , some body would share a drive etc etc. 

What is WSS and MOSS? 

Microsoft has divided share point products in two parts. One is called as WSS (Windows SharePoint services) and the other is MOSS (Microsoft Office SharePoint server). WSS is the platform on which MOSS is built. The WSS part is licensed through Windows 2003 server and it does not cost. MOSS is separate product by itself and it needs licensing and it has a good amount of cost J . WSS is good for small team and small projects. MOSS has extra functionalities in other words value added services. So the choice between WSS and MOSS will depend on budget of the project and the VAS provided by MOSS. 

How does WSS actually work? 

WSS does not work in an isolated fashion. It needs help of two more products IIS (Internet Information Server) and SQL Server.

How does WSS work with IIS? 

In order to understand how WSS works with IIS we need first understand the concept of "HttpHandlers and HttpModules".

Using the HttpHandlers and HttpModules request is first passed through the Share Point runtime and then passed to the ASP.NET runtime (aspnet_isapi.dll).


If you open the web.config file of a WSS enabled IIS web application you can see the application run time handlers and modules.
<httpHandlers>
<add verb="GET,HEAD,POST" path="*" type="Microsoft.SharePoint.ApplicationRuntime.SPHttpHandler, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
....
...
</httpHandlers>

We have highlighted the application runtime module.
<httpModules>
<add name="SPRequest" type="Microsoft.SharePoint.ApplicationRuntime.SPRequestModule, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
...
...
</httpModules> 


What is site and site collection? 

Share point is all about enterprise data. When we talk about enterprise data it looks some as shown in the figure below. In other words grouping and sub groupings of data.
SharePoint extends the IIS web application structure to accommodate the above defined data structure using site and site collections. We will see in the later section how to create site collections.
SharePoint extends the IIS web application structure to accommodate the above defined data structure using site and site collections. We will see in the later section how to create site collections.
What is the main advantage of using site collections? 
As said previously SharePoint is all about data and data should properly authenticated / authorized to proper users. By defining the structure in site and site collection we can now define roles and responsibilities according to data. For instance in the above figure we will assign all HR user to payroll, recruitment and assessment site. These users will not be assigned to account site collection. Same holds true for accounts user.

So when you design your hierarchy of site and site collection you need to keep in mind the enterprise hierarchy structure and design the same accordingly. 


What is the use of SQL Server in share point? 

SQL Server is used to store content and configuration information. We have two types of databases one is the content database and the other is the configuration database. We had said previously that content is according to every site. So every site has his own content database. For instance if we have a payroll site and recruitment site they have their own content database. Configuration database is for the entire site as they are used in web farms, site configuration and lot of other things which are generic and common across all the sites.
What is the concept of virtual path provider? 
Any project has two parts one is the standard and common part and the other is the customized version. In ASP.NET we have two types of pages for any project one is common ASPX pages and the other is customized ASPX pages. Common pages are stored on file directories while customized versions of pages are stored in content database.

So in other words we need an abstract mechanism by which we can render pages from SQL Server content database and also from the virtual directories. This is achieved by using the virtual provider provided by SharePoint. So for all customized pages virtual provider reads from the content database and passes the same to the ASP.NET runtimes. For all common pages it goes to the directory, parses it and the passes the same across to the ASP.NET runtime.

Virtual provider is an abstraction which loads the page from the content or the file system depending on whether it's customized or common pages and passes the same to the ASP.NET runtime.

What is the concept of ghosting and unghosting in SharePoint?
In SharePoint most of the site pages derive from templates. The custom pages only store the difference between them. The template is loaded in memory and applied to the custom pages on fly. In other words the template is stored in a cache. This definitely brings in performance and flexibility. Flexibility is in terms that when we change the template page it's applied to all custom pages. These pages are loaded from the file system. So pages which are loaded from the file system are termed as ghosted pages.
If the page data is loaded from the content database it's termed as unghosted pages.

As a note let me clarify the concept of document and content table as we are already trying to understand the concept of ghosting and unghosting. As we know that SharePoint stores all pages in the database. Looking from a 50,000 feet it has two tables one is the document table which has the entry of page and the other is the content which has the source code of the ASPX page.

So when a page is requested it first checks in the document table and then goes to the content table to load the page. If it does not find data of the page it goes to the file directory to load the page. This loading is done by ASP.NET runtime himself. But if there is data present in the content table then it's loaded by the 'safe mode' parser.


What is the concept of safemodeparser in ASP.NET?
As said the previous section there are two tables one is the document and the other content. If the page is stored in the content database it's loaded by the SafeModeParser which is page parser provided by SharePoint. If there is no data found in the content it's loaded from the file directory by simple ASP.NET runtime. 
What is the concept of Site pages and Application pages?
Site pages are customized pages and are saved in to content database. So when you use the SharePoint designer to make custom changes it saves the changes in to content database. If you want to make generic pages in a site collection which will be used by every one, like for instance the 'Settings.aspx' page then you need to use application pages.

In other words Site pages are nothing but customized pages stored in content, while application pages are generic pages which will be used by all the sites in a site collection.
Q. How does Client object model works?
Ans. When we use SharePoint client API’s to perform a specific task, the SharePoint Foundation 2010 managed client object model bundles up these uses of the API into XML and sends it to the server that runs SharePoint Foundation. The server receives this request, and makes appropriate calls into the object model on the server, collects the responses, forms them into JavaScript Object Notation (JSON), and sends that JSON back to the SharePoint Foundation 2010 managed client object model. The client object model parses the JSON and presents the results to the application as .NET Framework objects (or ECMAScript objects for ECMAScript).
Q. How many types of Client Object model extension are available in 2010 and when would you use one or the other.
Ans. To develop rich client side solutions, three set of client-side APIs has been introduced in the Microsoft.SharePoint.Client namespace. The three APIs are targeted for three different types of clients.
1. .net Managed applications – These are used when we have to create console applications or window applications, web applications which are not running inside SharePoint Contex.
2. For Silverlight applications
3. ECMAScript – It is a client object model extension for using with JavaScript or JScript. This is used for creating applications which are hosted inside SharePoint. For example, web part deployed in SharePoint site can use this JavaScript API for accessing SharePoint from browser using JavaScript.

Q. What is difference between Load() and LoadQuery() methods ?
Ans. Load method populates the client object directly with what it gets data from the server i.e. a collection object like ListItemCollection etc. but LoadQuery returns the data as a completely new collection in  IEnumerable format. Other major difference is that the Collections that you load using the Load() method are eligible for garbage collection only when the client context variable itself goes out of scope where as, in  these collections go out of scope at the end of  IEnumerable<List> list.
Q. How can you write efficient and better performing client object applications ?
Ans. You can always use Lambda expressions in your queries to return only specific properties that will be used in your block. You can also use LoadQuery() method and specify multiple levels of properties to load for e.g. while returning specific properties of the lists using LoadQuery(), you can also specify the fields to return from each list to optimize the data access.
Q. What are the Authentication methods for your client object model application ?
Ans. Basically there are three (3) authentication options you can use when you’re working with the Client Object Model in SharePoint 2010:
* Anonymous
* Default
* FormsAuthentication

You can specify clientContext.Authentication = Anonymous\Default\FormsAuthentication, If you do not choose an authentication method in your code, the application will default to using the client’s Windows Credentials (DefaultCredentials).
Q. How do you access ECMAScript object model API’s ?
Ans. The ECMAScript library is available in a number of JS files in the LAYOUTS folder. The main file among number of .js files is SP.js. When you include this file in the APSX page using a ScriptLink control, all other required JS files are loaded automatically. By linking SP.js to your page, the SP namespace gets registered. SP is the SharePoint namespace that contains all objects. For debugging purposes every js file also has a ‘debug’ equivalent in the same folder.

Q. What is the purpose of calling clientContext.ExecuteQuery() ?

Ans. ExecuteQuery gives you the option to minimize the number of roundtrips to the server from your client code. All the components loaded into the clientcontext are executed in one go.
Q. Why would you use LINQ over CAML for data retrieval?
Ans. Unlike CAML, with LINQ to SharePoint provider, you are working with strongly typed list item objects. For example, an item in the Announcements list is an object of type Announcement and an item on a Tasks list is an object of type Task. You can then enumerate the objects and get the properties for your use. Also, you can use LINQ syntax and the LINQ keywords built into C# and VB for LINQ queries.
Q. Can we use our custom master page with the application pages in SharePoint 2010 ?
Ans. With 2010, you can now set whether the pages under _Layouts use the same Master Page as the rest of your site. You can enable or disable this functionality through the web application settings in Central Administration. This however, is not applicable to your custom application pages. If you want your custom applictaion page to inherit the site master page you must derive it from Microsoft.SharePoint.WebControls.LayoutsPageBase class.
Q. What are WebTemplates and Site Definitions ?
Ans. Site definitions consist primarily of multiple XML and ASPX files stored on a front-end Web server in folders under the %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\SiteTemplates directory.
Custom Web templates on the other hand, are stored in the database, and are created using an existing site, with or without its specific content, as a model. This provides a means for reusing sites that you have customized.In some ways, Web templates continue to depend, throughout their lifecycle, on the site definition that is their ultimate foundation.

Q. How do you write to SharePoint ULS logs in 2010 ?
Ans. In SharePoint Foundation, ULS exposes configurable settings in two ways, through the – Object model and Windows PowerShell cmdlets. For writing to SharePoint ULS logs developers can can use Diagnostics Service, which will make the customized categories viewable in the administrative UI for our errors.
or they can use the number of cmdlets available for accessing ULS logs using powershell. Some of the cmdlets are Get-SPDiagnosticConfig ,Get-SPLogEvent etc.


Q. What does CMDUI.XML contain?
Ans. The definitions for the out-of-the-box ribbon elements are split across several files in the SharePoint root, with TEMPLATE\GLOBAL\XML\CMDUI.XML being the main one.
Q.  What has Changed in SharePoint 2010 Object model?
Ans. Microsoft has replaced the “12 hive” structure that we had in SharePoint 2007 with “14 Hive” structure in 2010.
It has apparently added four new folders to its hive.
The Folders are :
* Policy
* UserCode
* WebClients
* WebServices

Q. How would you deploy WebPart Using Windows PowerShell?
Ans. At the Windows PowerShell command prompt (PS C:\>), type the below command :
Install -SPWebPartPack -LiteralPath “FullPathofCabFile” -Name “Nameof WebPart”
Q. How would you re-deploy the old custom solutions in SharePoint 2010.What Changes are needed to the old Solution files.
Ans. SharePoint 2010 object model contains many changes and enhancements, but our custom code will still compile and, will run as expected. You should however, rewrite and recompile any code that refers to files and resources in “12 hive”.
For Details See :
SharePoint Object Model – Backward Compatibility

Q. How would you add a link in the Ribbon?
Ans. You can add any link or Custom Action under any of the existing tabs of the ribbon or can create a new a new tab and place your links under it.
Q. What does CMDUI.XML contain?
Ans. The definitions for the out-of-the-box ribbon elements are split across several files in the SharePoint root, with TEMPLATE\GLOBAL\XML\CMDUI.XML being the main one.
Q. What are the Disadvantages of Using LINQ in your Code?
Ans. LINQ translates the LINQ queries into Collaborative Application Markup Language (CAML) queries thus adding an extra step for retrieving the items.
Q. What is different with SharePoint 2010 workflows ?
Ans. Some of the additions in workflow model are :
1. SharePoint 2010 workflows are build upon the the workflow engine provide .Net Framework 3.5.
2. In addition to the SharePoint lists we can now create workflows for SharePoint sites as well.
3. SharePoint Designer 2010 also has a new graphical workflow designer for designing workflows and deploying them directly to SharePoint.
4. Another Improvement in SharePoint Designer 2010 is that it now allows you to edit the out-of-the-box workflows that come with SharePoint.
Q. How does Ribbon works ?
Ans. A file called CMDUI.XML stays at the web front end which contains the Out-of-Box site wide Ribbon implementation i.e. all the Ribbon UI for the entire site. In addition to this you have a CustomAction for each ribbon component. These CustomActions have CommandUIExtentions block which has CommandUIDefinitions and CommandUIHandlers which make up the activity of the ribbon component. So, when the ribbon is loaded the CommandUIDefinition merges with Out-of-Box definition in the CMDUI.XML
Q. How will you use WebParts or other solutions Created in SharePoint 2007 in SharePoint 2010 ?
Ans. In SharePoint 2010 the 12 hive is now replaced by 14 hive, So we will rewrite and recompile any code that refers to files and resources in “12″ hive. In addition to we must recompile custom code written for Windows SharePoint Services 3.0 and Office SharePoint Server 2007 that does not run on IIS.
Q. What is the advantage in using Windows PowerShell over stsadm in SharePoint 2010 ?
Ans. Unlike stsadm, which accept and return text, Windows PowerShell is built on the Microsoft .NET Framework and accepts and returns .NET Framework objects.Windows PowerShell also gives you access to the file system on the computer and enables you to access other data stores, such as the registry and the digital signature certificate stores etc..
Q. What is REST ? How is it used in SharePoint 2010 ?
Ans. REST (Representational State transfer) is a protocol (powered by ADO.NET services) which is used for getting data out of sharepoint via Url. It is mostly used to access data from sharepoint even when you are not in the sharepoint context.
Q. What datatype is retured by REST ?
Ans. REST does not return an object of type SharePoint Site\List. Instead, it returns an XML output.
Q. What is a workflow?
Ans. Workflows are the way an organization functions, a series of actions that correspond to a work process, such as the process for purchase orders.SharePoint 2010 helps you automate these workflows, thereby increasing the efficiency and productivity of the organization.
Q. What are the types of workflow that you can design in SharePoint 2010.
Ans. you can design List Workflows, Reusable List Workflows and Site workflows using SharePoint designer 2010.
Q. What Reusable List Workflows and Site workflows ?
Ans.
Reusable List Workflows -
You can create a reusable list workflow (reusable workflow) in the top-level site in the site collection, and that workflow can be made globally reusable — meaning that the workflow can be associated to any list, library, or content type in the site collection. You can also create a reusable workflow in any subsite in the site collection; this workflow is available for reuse in that particular subsite.
Site workflows - A site workflow is associated to a site — not to a list, library, or content type. So unlike most workflows, a site workflow is not running on a specific list item. Because of this, many of the actions that are available for items not available for site workflows.
Q. Can you modify the Out-of-Box workflows in SharePoint 2010 ?
Ans. In SharePoint 2010, you have an option to customize the Out-of-Box workflows. The four most popular workflows in SharePoint Server 2007 — the Approval, Collect Feedback, Collect Signatures, Publishing Approval workflows — have been completely rebuilt as declarative reusable workflows, meaning that they are now fully customizable in SharePoint Designer 2010.
Q. What are events, actions, conditions and steps?
Ans. Lets look at this one by one.
Events - An event is what starts or initiates a workflow. Events can also be used to manage the timing of actions within a workflow, such as waiting for the status of an item to change. There are three events that can start a workflow:
* An item is created.
* An item is changed.
* A workflow participant clicks a start button on the SharePoint site.

Actions –
An action is the most basic unit of work in a workflow. SharePoint Designer 2010 provides a set of ready-made, reusable actions for you to incorporate into your workflow.

For example, your workflow can:
* Create, copy, change, or delete list items (including documents).
* Check items in or out.
* Send an e-mail message.

Conditions - When you design a workflow, you can use the workflow editor to create rules that apply conditional logic to SharePoint sites, lists, items and content types. A rule establishes a condition where the workflow performs the associated action only if that condition is true. For example, you can create a rule where the workflow sends a reviewer an e-mail message only if an item is created by a specific person.
Q. What are Parallel and Serial actions ?
Ans. When you have more than one action associated with a condition, the actions can be set up to run at the same time (parallel) or one after another (serial), the default.
Q. What are the Types of forms associated with the workflow ?
Ans. With SharePoint Designer 2010, you can create three types of workflow forms:
Initiation form – An initiation form gathers information from the workflow participant when they start the workflow. It is automatically generated when you create the workflow in SharePoint Designer 2010. Initiation forms are displayed to users when they manually start a workflow on a given SharePoint item. With an initiation form, users can specify additional parameters or information about the workflow as it applies to the given SharePoint item.

Task form –
A custom task form allows workflow participants to interact with tasks in the Tasks list specified for the workflow. With the Custom Task Wizard, you can easily create custom form fields and add them to a custom task form. When you finish designing the workflow, SharePoint Designer 2010 automatically generates the InfoPath or ASP.NET forms for your custom tasks.

Reusable workflow – association form – A reusable workflow, by default, only provides the fields common to all items, such as Created and Modified by. This is because a reusable workflow isn’t by default associated with a list, library, or content type. An association form enables you to associate fields with a reusable workflow so that the fields will be available when you design and run the workflow.
Q. When are these forms get created ? And how do you customize it ?
Ans. SharePoint Designer 2010 automatically generates the forms, but you can customize them by going to the settings page for the workflow, in the Forms section, click the form you want to customize. Workflow forms are either InfoPath or ASP.NET pages. They are stored on the SharePoint site with the workflow source files.
Reference Links

Q. What are the main namespaces in SharePoint 2007 ?
Ans. In Sharepoint Object model there are two Important namespaces. The Microsoft.Office.Server namespace is the root namespace of all Office Server objects and Microsoft.SharePoint is the root namespace for all WSS objects.
Q. How Do you create custom column in Sharepoint object model ?
Ans. To create custom filed types you need to follow the below steps :
1. Create a Field Type Definition
2. Create a Field Class
3. Create a Rendering Control Class
4. Create One or More Rendering Templates
5. Create a Field Value Type
6. Create an Editing Control

Q. How do I use and deploy code behind files with my custom pages in SharePoint ?
Ans. You do not deploy code behind files in along with your custom aspx or layouts page Instead, you can just have the aspx page inherit from the compiled .dll of the project containing that code file.
Q. How can you get the filtered items from a SharePoint list programatically?
Ans. You can either use SPQuery with the where condition or you can set a up a filtered view in the list itself and then access the view in your solution using SPView class.
Q. What will you do for fast and efficient retrieval of items from sharepoint lists ?
Ans. You can use either SPquery object from SPquery class or you can use PortalSiteMapProvider class. PortalSiteMapProvider class includes a method called GetCachedListItemsByQuery that retrieves data from a list based on an SPQuery object that is provided as a parameter to the method call. The method then looks in its cache to see if the items already exist. If they do, the method returns the cached results, and if not, it queries the list, stores the results in cache and returns them from the method call.
Q. What are Activation Dependencies in SharePoint fetaures ?
Ans. A Feature activation dependency expresses a requirement in the relationship between two Features. You generally use activation dependencies for two purposes:
1. To specify that your feature should not be activated unless another feature gets activated. It means your feature activation is dependent of the activation of some other feature. To implement this all you need to do is add a <ActivationDependencies> tag in your feature.xml file and add a ActivationDependency under it. ActivationDependency however needs FeatureId i.e. the guid of the parent feature on whom your feature is dependent.
2. For Feature grouping concepts. That means when one Feature is activated, other Features can also be activated.

Q. When do you use SPSiteDataQuery ?
Ans. You can use SPSiteDataQuery when you need to extract data from more than one list\library in your site collection. The data is extracted on the basis of the query you write and is returned as a Datatable.
Q. Can you specify a particular list for SPSiteDataQuery ?
Ans. You can also specify the GUID for the lists\libraries you want to query against in  lists tag.
Q. What are the best practices for SharePoint development.
Ans. Some of the best practices are:
1. You should always dispose SPsite and SPWeb objects, once you refer them in your code. Using the “Using” clause is recommended.
2. Use RunwithelevatePrivilages to avoid errors for end users.
3. Try writing your errors to SharePoint error logs (ULS Logs). Since it’s a bad idea to fill-up event log for your production environment.
4. Use SPQuery instead of foreach loop while retrieving Items from the list.
5. Deploy additional files used in your webpart to 12 hive. Use your solution package to drop the files in 12 hive. Also, make sure that all the references (for e.g. Css or .js files) get removed when the solution is retracted.
Q. How should I deploy a webpart, a master page and a layouts page in one solution package ?
Ans.Create different features file for each component and add Modules for them in their elements file. all features can be added in one solution package.
What is a SPSite and SPWeb object, and what is the difference between each of the objects? 

The SPSite object represents a collection of sites (site collection [a top level sites and all its subsites]). The SPWeb object represents an instance SharePoint Web, and SPWeb object contains things like the actual content. A SPSite object contains the various subsites and the information regarding them.
 
How would you go about getting a reference to a site?

Select For Unformatted Code
C#:
oSPSite = new SPSite("http:/server");
oSPWeb = oSPSite.OpenWeb();
Internet Explorer 6, Netscape Navigator 6.2 or later.
What does a SPWebApplication object represent? 

The SPWebApplication objects represents a SharePoint Web Application, which essentially is an IIS virtual server. Using the class you can instigate high level operations, such as getting all the features of an entire Web Application instance, or doing high level creation operations like creating new Web Applications through code.

Would you use SPWebApplication to get information like the SMTP address of the SharePoint site?
Yes, since this is a Web Application level setting. You would iterate through each SPWebApplication in the SPWebApplication collection, and then use the appropriate property calls (OutboundMailServiceInstance) in order to return settings regarding the mail service such as the SMTP address.
How do you connect (reference) to a SharePoint list, and how do you insert a new List Item? 

Select For Unformatted Code
C#:
1. using(SPSite mySite = new SPSite("yourserver"))
2. {
3. using(SPWeb myWeb = mySite.OpenWeb())
4. {
5. SPList interviewList = myWeb.Lists["listtoinsert"];
6. SPListItem newItem = interviewList.Items.Add();
7. 8. newItem["interview"] = "interview";
9. newItem.Update();
10. }
11. }
How would you loop using SPList through all SharePont List items, assuming you know the name (in a string value) of the list you want to iterate through, and already have all the site code written? 

Select For Unformatted Code
C#:
1. SPList interviewList = myWeb.Lists["listtoiterate"];
2. foreach (SPListItem interview in interviewList)
3. {
4.  Here you put any condition to filter the values
            If(Interview[“name”].ToString()==”test”)
{
Add to ArrayList
}

“name” is column name in particular list
}

Another method use can CAML Query to get values from list. This method is faster compared to above

SPList interviewList = web.Lists["listtoiterate"];
SPQuery spQuery = new SPQuery();
spQuery.Query = @”<Where>
  <Eq>
    <FieldRef Name="name" />
      <Value Type="Text">test</Value>
  </Eq>
</Where>”;

SPListItemCollection queryitems = interviewList.GetItems(spQuery);
What does AllowUnsafeUpdates do ?

If your code modifies Windows SharePoint Services data in some way, you may need to allow unsafe updates on the Web site, without requiring a security validation. You can do by setting the AllowUnsafeUpdates property.

C#:
using(SPSite mySite = new SPSite("yourserver"))
{
using(SPWeb myWeb = mySite.OpenWeb())
{
myWeb.AllowUnsafeUpdates = true;
SPList interviewList = myWeb.Lists["listtoinsert"];
SPListItem newItem = interviewList.Items.Add();

newItem["interview"] = "interview";
newItem.Update();
}
}
What does RunWithElevatedPrivileges do?

Assume that you have a Web Part in which you want to display information obtained through the Windows SharePoint Services object model, such as the name of the current site collection owner, usage statistics, or auditing information. These are examples of calls into the object model that require site-administration privileges. Your Web Part experiences an access-denied error if it attempts to obtain this information when the current user is not a site administrator. The request is initiated by a nonprivileged user. you can still successfully make these calls into the object model by calling the RunWithElevatedPrivileges method provided by the SPSecurity class.
C#:
SPSite siteColl = SPContext.Current.Site;
SPWeb site = SPContext.Current.Web;
SPSecurity.RunWithElevatedPrivileges(delegate() {

using (SPSite ElevatedsiteColl = new SPSite(siteColl.ID)) {
using (SPWeb ElevatedSite = ElevatedsiteColl.OpenWeb(site.ID)) {
string SiteCollectionOwner = ElevatedsiteColl.Owner.Name;
string Visits = ElevatedsiteColl.Usage.Visits.ToString();
string RootAuditEntries =
ElevatedSite.RootFolder.Audit.GetEntries().Count.ToString();
}
}

});

In some place you will get error “Access Denied”  like when you try to execute caml query or something in that case if ypu place you caml query code inside this RunWithElevatedPrivileges delegate then automatically it will take system account rights and run the code.
What is ServerUpdate() and SystemUpdate() ?

Any changes in the list, i.e. new addition or modification of an item.. the operation is complete by calling the Update method.


But if a List is set to maintain versions .. and you are editing an item, but don't want to save it as a new version, then use the SystemUpdate method instead and pass in 'false' as the parameter.

Here there are some SharePoint Object model classes.
In the top SPFarm class is there.

SPFarm: This reference the entire SharePoint Server Farm.
By using this you can create a new farm or you can connect to a existing a existing farm.
Namespace: Microsoft.SharePoint.Administration

SPServer: By using this class you can browse through the collections of servers belongs to the Farm.

SPSite: Represent a Site collection.

SPWeb: Represent a web site.

SPUserToken: The SPUserToken class represents a token for a valid SharePoint user.

SPList: SPList corresponds to a single list instance, whether that is a list of items or a document library.

SPListItem: This defines a reference to a specific item of a list.

SPDocumentLibrary: This type represents a document library.

SPFile: This class is used to enumerate the files contained in a document library.

SPPrincipal: This class is the parent class for SPGroup and SPUser.

SPControl: This class we need while developing web controls or Web Parts.

SPContext: This is a very useful class and it has some direct methods to access useful information about current requests.
Creating a subsite
SPWeb mySite = SPContext.Current.Web;
SPWebCollection mySiteCollection = mySite.Webs;
uint lcid = mySite.Language;
string templateName = "WIKI#0";
mySiteCollection.Add("Nani Site", "Nani", "Site Created using object model", lcid, templateName, false, false);
mySite.Dispose();
Creating a list
SPSite mySiteCollection = SPContext.Current.Site;
SPWeb mySite = mySiteCollection.OpenWeb();
SPListCollection myListCollection = mySite.Lists;
myListCollection.Add("Niru6", "created using object model",SPListTemplateType.Contacts);
Show all top level sites in farm
SPWebServiceCollection myservices = new SPWebServiceCollection(SPFarm.Local);
foreach (SPWebService myservice in myservices)
{
SPWebApplicationCollection myWebAppCollection = myservice.WebApplications;
foreach (SPWebApplication mywebApp in myWebAppCollection)
{
SPSiteCollection mySiteCollection = mywebApp.Sites;
SPSite mySite = mySiteCollection[0];
Label1.Text += mySite.RootWeb.Url + "";
}
}
Return the collection of site collections in a SharePoint Web application
SPWebApplication myWebApp = SPContext.Current.Site.WebApplication;
SPSiteCollection mySiteCollection = myWebApp.Sites;
foreach (SPSite mySite in mySiteCollection)
{my
Label1.Text += mySite.RootWeb.Title + "";
mySite.Dispose();
}
To return the collection of The all the Webs or sites within a site collection, including the top-level site and all subsites
SPWebApplication myWebApp = SPContext.Current.Site.WebApplication;
SPSiteCollection mySiteCollection = myWebApp.Sites;
foreach (SPSite mySite in mySiteCollection)
{
SPWebCollection myWebCollection = mySite.AllWebs;
foreach (SPWeb myWeb in myWebCollection)
{
Label1.Text += mySite.Url + " " + myWeb.Title + "";
myWeb.Dispose();
}
mySite.Dispose();
}
To return the all the subsites and lists of the current site
SPSite mySite = SPContext.Current.Site;
SPWebCollection myWebCollection = mySite.AllWebs;
foreach (SPWeb myWeb in myWebCollection)
{
SPListCollection myListCollection = myWeb.Lists;
foreach (SPList myList in myListCollection)
{
Label1.Text += myWeb.Title +" " + myList.Title + "";
}
myWeb.Dispose();

}
Show all roles in a site
SPSite mySite = SPContext.Current.Site;
SPWeb myWeb = mySite.RootWeb;
SPRoleDefinitionCollection myRoleCollection = myWeb.RoleDefinitions;
foreach (SPRoleDefinition myRole in myRoleCollection)
{
Label1.Text += myRole.Name + "";
}
Show all alerts in a site
SPWeb mySite = SPContext.Current.Web;
SPAlertCollection myAlertCollection = mySite.Alerts;
foreach (SPAlert myAlert in myAlertCollection)
{
Label1.Text += myAlert.Title + "";
}
Show all lists in a site
SPWeb mySite = SPContext.Current.Web;
SPListCollection myListCollection = mySite.Lists;
foreach (SPList myList in myListCollection)
{
Label1.Text += myList.Title + "";
}
Show all list templates in a site
SPSite mySite = SPContext.Current.Site;
SPWeb myWeb = mySite.RootWeb;
SPListTemplateCollection myTemplateCollection = myWeb.ListTemplates;
foreach (SPListTemplate myTemplate in myTemplateCollection)
{
Label1.Text += myTemplate.Name + " " + myTemplate.Type + "";
}
Show all fields in a list
SPSite mySite = SPContext.Current.Site;
SPWeb myWeb = mySite.RootWeb;
SPList myList = myWeb.Lists["Niru3"];
SPFieldCollection myFieldCollection = myList.Fields;
foreach (SPField myField in myFieldCollection)
{
Label1.Text += myField.Title + "";
}
Show all items in a list column
SPSite mySite = SPContext.Current.Site;
SPWeb myWeb = mySite.RootWeb;
SPList myList = myWeb.Lists["Niru3"];
SPListItemCollection myItemCollection = myList.Items;

foreach (SPListItem myItem in myItemCollection)
{

Label1.Text += myItem["Last Name"].ToString() + "";

}
Delete all items from a list
When using a for Loop, if you wish to remove an item from the collection you are iterating through it can be done very easily. When using foreach you will get an exception stating that the item cannot be removed
Refer :
Link
SPSite mySite = SPContext.Current.Site;
SPWeb myWeb = mySite.RootWeb;
SPList myList = myWeb.Lists["Niru3"];
for (int i = myList.Items.Count - 1; i >= 0; i--)
{
myList.Items.Delete(i);
}
Show all groups in a site
SPSite mySite = SPContext.Current.Site;
SPWeb myWeb = mySite.RootWeb;
SPGroupCollection myGroupCollection = myWeb.Groups;
foreach (SPGroup myGroup in myGroupCollection)
{
Label1.Text += myGroup.Name + "";

}
Delete a item in a list based on condition
SPSite mySite = SPContext.Current.Site;
SPWeb myWeb = mySite.RootWeb;
SPList myList = myWeb.Lists["Niru3"];
for (int i = myList.Items.Count - 1; i >= 0; i--)
{
if (myList.Items[i]["Last Name"].ToString() == "Nani")
{
myList.Items.Delete(i);
}

}
Show all users in a group
SPSite mySite = SPContext.Current.Site;
SPWeb myWeb = mySite.RootWeb;
SPGroupCollection myGroupCollection = myWeb.Groups;
SPGroup myGroup = myGroupCollection["Viewers"];
SPUserCollection myUserCollection = myGroup.Users;
foreach (SPUser myUser in myUserCollection)
{
Label1.Text += myUser.Name + "
";
}
Show all users from all groups from user collection
SPSite mySite = SPContext.Current.Site;
SPWeb myWeb = mySite.RootWeb;
SPGroupCollection myGroupCollection = myWeb.Groups;
foreach (SPGroup myGroup in myGroupCollection)
{
SPUserCollection myUserCollection = myGroup.Users;
foreach (SPUser myUser in myUserCollection)
{
Label1.Text += myGroup.Name + "" + myUser.Name + "";
}

}
Show only blog sites
SPSite mySite = SPContext.Current.Site;
SPWebCollection myWebCollection = mySite.AllWebs;
foreach (SPWeb myWeb in myWebCollection)
{
if (myWeb.WebTemplate == "BLOG")
{
Label1.Text += myWeb.Title + "" ;
}
myWeb.Dispose();

}
Show services and status in sharepoint server farm
SPFarm myFarm = SPFarm.Local;
SPServiceCollection myServiceCollection = myFarm.Services;
foreach (SPService myService in myServiceCollection)
{
Label1.Text += myService.Name + " " + myService.Status + "
";
}
To get the timer jobs history for a particular service in the SharePoint 2010 farm
SPFarm myFarm = SPFarm.Local;
SPServiceCollection myServiceCollection = myFarm.Services;
foreach (SPService myService in myServiceCollection)
{
if (myService.DisplayName == "My Sample Service")
{
foreach (SPJobHistory entry in myService.JobHistoryEntries)
{
Label1.Text += "Job Definition Title - " + entry.JobDefinitionTitle + " : Status - " + entry.Status + " : Start Time - " + entry.StartTime + "
";
}

}
}
Get content database for all site collections
SPWebServiceCollection myWebServiceCollection = new SPWebServiceCollection(SPFarm.Local);
foreach (SPWebService myWebService in myWebServiceCollection)
{
SPWebApplicationCollection myWebApplicationCollection = myWebService.WebApplications;
foreach (SPWebApplication myWebApplication in myWebApplicationCollection)
{
SPContentDatabaseCollection myContentDatabaseCollection = myWebApplication.ContentDatabases;
foreach (SPContentDatabase myContentDatabase in myContentDatabaseCollection)
{
Label1.Text += myContentDatabase.Name + "
";
}
}

}
Add fields to list and add it to default view
SPWeb mySite = SPContext.Current.Web;
SPList myList = mySite.Lists.TryGetList("Niru2");
SPFieldCollection myFieldCollection = myList.Fields;
string strNewFieldName = myFieldCollection.Add("Native Place", SPFieldType.Text, false);
SPField oField = myFieldCollection.GetField(strNewFieldName);
SPView oView = myList.DefaultView;
SPViewFieldCollection colViewFields = oView.ViewFields;
colViewFields.Add(oField);
oView.Update();
Creating a new view in a list
SPWeb mySite = SPContext.Current.Web;
SPList myList = mySite.Lists.TryGetList("List_Name");

SPViewCollection myViewCollection = myList.Views;
string strViewName = "View_Name";
System.Collections.Specialized.StringCollection collViewFields = new System.Collections.Specialized.StringCollection();
collViewFields.Add("Field1_Name");
collViewFields.Add("Field2_Name");
collViewFields.Add("Field3_Name");
string strQuery = "" +
"1000";

myViewCollection.Add(strViewName, collViewFields, strQuery, 100, true, false,
Microsoft.SharePoint.SPViewCollection.SPViewType.Grid, false);

Source : MSDN
Creating a new content type and add it to a list, Adding the existing site columns to existing content type
- Check for duplicate content type, field, and list names.
- Create a new site content type.
- Add the content type to the site collection
- Create a site field to link to
- Link the content type to the field
- Commit changes to the database
- Create a list
- Apply the new content type to the list
o Add the new content type
o Remove the default content type
o Commit changes to the list
- Refer : Link
Delete recycle bin items
SPSite site = new SPSite(<>);
SPWeb web = site.RootWeb;
SPRecycleBinQuery q = new SPRecycleBinQuery();

q.RowLimit = Int32.Parse(<>);
q.OrderBy = SPRecycleBinOrderBy.Default;
SPRecycleBinItemCollection itemColl = web.GetRecycleBinItems(q);
foreach (SPRecycleBinItem item in itemColl)
{
Guid[] id = new Guid[1];
id[0] = item.ID;
itemColl.Delete(id);
}
Source: MSDN
• creating folder, uploading file to folder, deleting folder searching the folder in a doc lib
Refer to MSDN
Use about AllowUnsafeUpdates  :Refer this link
About Disposing objects :link
My Notes :
* (SPSite -> AllWebs)The AllWebs property of the SPSite class returns all the Web sites within a site collection, including the top-level site and all subsites.
* (SPWeb ->webs) To return a list of all the first-tier subsites beneath a specific Web site, use the Webs property of the SPWeb class.
* (SPWeb) openweb – return the site that is associated with the url that is used in SPSite constructor
* To return the collection of site collections in a SharePoint Web application, use the Sites property of the Microsoft.SharePoint.Administration.SPWebApplication class. Use properties of the Microsoft.SharePoint.SPContext class to return the current Web application.
* (SPWeb ->RootWeb)To return the top-level Web site of the current site collection, use the RootWeb property.
* close method — Closes the website at the end of a request and releases resources.
* Dispose method — Releases all resources used by the current instance of the website.
*  To Get the web site where the feature is activated.
SPWeb parentWeb = properties.Feature.Parent as SPWeb;
* when we use Rootweb and SPContext ie No explicit  dispose required.

Interview 1:

1. Why do you want to leave company
2. What type of authentication your project
3. Can it be possible to connect FBA to active directory.
4.  How we create webpart property
5. If you want to create a property in Active directory and map it to the search what you will do.
6. Serial and parrallel workflow.
7. what type of topology we have in sharepoint projects.
8. ghosting and unghosting
9. how we add a content type to page layouts. and what are the layouts.
10. Alternate Access Mappings
11. What are the detault databases SQL server has