Search This Blog

Loading...

Tuesday, June 4, 2013

SharePoint Interview Questions from Stack Overflow

In this blog, I am going to present some very awesome SharePoint interview questions collected from Stack Overflow—-one of my favorite technology forums. Moreover, I also collected some questions from other site, let say from internet. So thank you Stack Overflow, and the whole internet, especially SharePoint communities.

Enjoy!

Q: What is the difference betweenSystem.Web.UI.WebControls.WebParts.WebPart andMicrosoft.SharePoint.WebPartPages.WebPart?

A: Microsoft.SharePoint.WebPartPages.WebPart is provided in MOSS 2007 to provide backwards compatability with MOSS 2003 webparts. In MOSS 2007, it is recommended to use System.Web.UI.WebControls.WebParts.WebPartinstead.

Q. When running with SPSecurity.RunWithElevatedPrivileges (web context) what credentials are being used?

A. The App Pool Identity for the web application running SharePoint.

Q: Why would you use a custom column?

A: It allows you to re-use the column in multiple libraries. Particularly useful if you use a Choice type to restrict the user input to a predefined set of answers, and when that list of answers will likely change.

Q: Describe the difference between a list and a library.

A: Lists are collections of metadata or columns, that can have attached documents. Libraries are collections of documents (Excel, InfoPath, Word, etc.) plus optional metadata.

Q. When modifying a list item, what is the "main" difference between using SPListItem.Update() and SPListItem.SystemUpdate()?

A. Using SystemUpdate() will not create a new version and will also retain timestamps.

Q: What are "Features" and why should you know about them?
A: Anything from The concept of a "Feature" in SharePoint demonstrates an understanding.

Q. If you have an ItemUpdated or ItemUpdating event receiver and it causes an update to the item, how do you prevent another ItemUpdated and ItemUpdating event from being fired during your update?

A. Before performing your update, call DisableEventFiring(). After update, call EnableEventFiring().

Q: (i) Describe the purpose of a content type and; (ii) give an example of where they might be used.

A: (i) A content type groups a set of list columns together so that they can be reused in the same way across sites. (ii) They could be used as a set of metadata columns that need to be applied to every document in a site collection.

Q: When should you dispose SPWeb and SPSite objects? And even more important, when not?

A: You should always dispose them if you created them yourself, but not otherwise. You should never dispose SPContext.Current.Web/Site and you should normally not dispose SPWeb if IsRootWeb is true. More tricky constructs are things along the line of SPList.ParentWeb.

Q. What are the data types which are supported as Lookup column in SharePoint.

A. Only Single Line of Text and Calculated columns are supported as lookup columns.

Q: Name at least two shared services available in MOSS 2007

A: Shared Services Providers in MOSS 2007 can provide the following shared services:

  • User Profiles
  • Audiences
  • Personal Sites
  • Search
  • Excel Services
  • Forms Services
  • Business Data Catalog (Requires Enterprise Edition)

Q. What base classes do event receivers inherit from?

A:

  1. SPListEventReceiver, SPItemEventReciever, and SPWebEventReceiver inherit from the abstract base class SPEventReceiverBase.
  2. SPWorkflowLibraryEventReceiver inherits from SPItemEventReceiver.
  3. SPEmailEventReceiver inherits directly from System.Object.

Q. What is a site collection, why would you create a new site collection as opposed to a site?

A. Bit of a long answer, but they should know about site collection administration, quotas, seperation of assets, security model etc.

Q. What is the difference between MOSS & WSS

A. MOSS uses the Shared Service Provider for search, profile import, etc… (see the answers posted by Lars Fastrup for a more complete list)

Q: What are the built in ways to backup a SharePoint install?

A: Through the central administration and the stsadm command

Q: (more advanced) You've created and deployed a Web Part, when you deploy to the server you get a page saying your Web Part couldn't be loaded, click here to go to the Web Part maintenance page, etc. to disable the web part. What step(s) should you take to get a stack dump from your web part instead of that error page?

A: Go to the web.config file for your website and find the CallStack Attribute in the SafeControls element and set the value to true.

Q. How would you create a Master/Detail page?

A. Creating a Content type inheriting from Folder Content Type for the master, and another Content type inheriting from Item and using them both on a List

Q: What is the performance impact of RunWithElevatedPrivileges?

A: RunWithElevatedPrivileges creates a new thread with the App Pool's credentials, blocking your current thread until it finishes.

Q: What is a way of elevating SharePoint privileges without using RunWithElevatedPrivileges?

A: Pass the System Account User Token from the SPContext to the SPSite constructor.

A majority of times a developer can accomplish what they need using this method without needlessly elevating network credentials.

Disclaimer: All of these SharePoint interview questions are from Stack Overflow, and condensed by me. The original questions, comments of the questions as well, can be found from that web site.


--
Sudipto Roy
Asst. Manager - SharePoint

Thursday, May 23, 2013

Web Part life cycle in SharePoint 2010


 

OnInit: This method handles initialization of the control.
OnLoad: This event handles the Load event. This is also used for initialize the control but is not intended for loading data or other processing functionality.
CreateChildControls: This is the most popular event in web part life cycle. This creates any child controls. So if you are adding any control to display then you have to write in this method.
EnsureChildControls: This method ensures that CreateChildControls has executed.
EnsureChildControls method must be called to prevent null reference exceptions.
SaveViewState: View state of the web part saved.
OnPreRender: This method handles or initiates tasks such as data loading that must complete before the control can render.
Page.PreRenderComplete: The page fires the PreRenderComplete event after all controls have completed their OnPreRender methods.
Render: This method is used to render everything.
RenderContents: Renders the contents of the control only, inside of the outer tags and style properties.
OnUnload: Performs the final cleanup.
Example On Web Part Life Cycle:
---------------------------------------
using System;
using System.ComponentModel;   
using System.Web;
 usingSystem.Web.UI;
using System.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingMicrosoft.SharePoint;
usingMicrosoft.SharePoint.WebControls;
namespaceMorClsWPS.WPLifeCycle1{
[
ToolboxItemAttribute(false)]
public class WPLifeCycle1 : WebPart{//variblesprivate stringstrResults; 
private TextBox txtContent; 
private Button btnShow;
private Label lblErrMsg;
/// <summary>/// 1 st EVENT IN WEB PART /// During the initialization, configuration values that were marked as webbrowsable/// and set through the webpart task pane are loaded to the webpart/// </summary>/// <param name="e"></param>protected override void OnInit(EventArgs e){
try{this.strResults += "onInit Method <br>";
base.OnInit(e);}
catch (Exception ex){
this.lblErrMsg.Text = ex.Message.ToString();}
}
/// <summary> /// 2 nd EVENT IN WEB PART /// /// Viewstate is a property inherited from System.Web.UI.Control . /// The viewstate is filled from the state information that was previously serialized /// would like to persist your own data within webpart /// </summary> /// <param name="savedState"></param>protected override void LoadViewState(objectsavedState){
try{
strResults +=
 "LoadViewState<br>";
object[] viewstate = null;
if (savedState != null){
viewstate = (
object[])savedState;
base.LoadViewState(viewstate[0]);strResults += (
string)viewstate[1] + "<br>";}
}
catch (Exception ex){
this.lblErrMsg.Text = ex.Message.ToString();}
}
/// <summary> /// 3 rd EVENT IN WEB PART MANAGER /// All of the constituent controls are created and added to the controls collection /// </summary>protected override voidCreateChildControls(){
try{
strResults +=
 "CreateChildControls<br>"; //creating error label controls this.lblErrMsg = new Label();
this.lblErrMsg.ID = "lblErrMsg";
this.lblErrMsg.Text = string.Empty;
this.Controls.Add(lblErrMsg); //creating text controlsthis.txtContent = new TextBox();
this.txtContent.ID = "tbxText";
this.txtContent.Text = string.Empty;
this.Controls.Add(txtContent); //creating button controlsthis.btnShow = new Button();
this.btnShow.ID = "btnShow";
this.btnShow.Text = "Check Text Value";
this.btnShow.Click += new EventHandler(btnShow_Click);
this.Controls.Add(btnShow);}
catch (Exception ex){
this.lblErrMsg.Text = ex.Message.ToString();}
}
/// <summary> /// butoon click event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> privatevoid btnShow_Click(object sender, EventArgs e){
try{this.strResults += "button click event has fired<br>";}
catch (Exception ex){
this.lblErrMsg.Text = ex.Message.ToString();}
}
/// <summary> /// 4 th EVENT IN WEB PART /// Perform actions common to all requests, such as setting up a database query ///At this point, server controls in the tree are created and initialized, the state is restored, /// and form controls reflect client-side data. /// </summary> /// <param name="e"></param> protected override void OnLoad(EventArgs e) { 
try { 
this.strResults += "Onload<br>"; 
base.OnLoad(e); } 
catch (Exception ex) { 
this.lblErrMsg.Text = ex.Message.ToString(); } 
}
/// <summary> /// 5 th EVENT IN WEB PART/// Perform any updates before the output is rendered. /// Any changes made to the state of the control in the pre-render phase can be saved///while changes made in the rendering phase are lost. ///</summary> /// <param name="e"></param> protected override voidOnPreRender(EventArgs e) { 
try { 
this.strResults += "OnPreRender<br>"; 
base.OnPreRender(e); } 
catch (Exception ex) { 
this.lblErrMsg.Text = ex.Message.ToString(); } 
}
/// <summary> /// 6 th EVENT IN WEB PART /// store cutom data within a web part's viewstate /// The ViewState property of a control is automatically persisted to a string object after this stage. /// This string object is sent to the client and back as a hidden variable. /// For improving efficiency, a control can override /// the SaveViewState method to modify the ViewState property. /// once viewstate is saved,the control webpart can be removed from the memory of the server. ///webpart receives notification that they are about removed from memory through dispose event /// </summary> /// <returns></returns> protected override object SaveViewState() { 

this.strResults += "SaveViewState<br>"; 
object[] viewstate = new object[2]; viewstate[0] =base.SaveViewState(); viewstate[1] = 
"MyTestData"; 
return viewstate; }
/// 7 th EVENT IN WEB PART/// Generate output to be rendered to the client. /// you can create user interface of your webpart using html table. /// You can apply your css classes here itself /// </summary> /// <param name="writer"></param> publicoverride void RenderControl(HtmlTextWriter writer) { 
try { 
//this method ensure all created child controlsEnsureChildControls(); this.strResults += "RenderControl<br>"; 
//table start writer.Write("<table id='tblTest'align='center' cellpadding='0' cellspacing='0' border='1' width='100%'>");writer.Write(
"<tr>"); writer.Write(
"<td>"); writer.Write(strResults); 
writer.Write(
"</td>"); writer.Write(
"</tr>"); //row 2 writer.Write("<tr>"); writer.Write(
"<td>"); 
this.txtContent.RenderControl(writer); writer.Write(
"</td>"); writer.Write(
"</tr>"); //row 3 writer.Write("<tr>"); writer.Write(
"<td>"); 
this.btnShow.RenderControl(writer); writer.Write(
"</td>"); writer.Write(
"</tr>"); //row 4 writer.Write("<tr>"); writer.Write(
"<td>"); 
this.lblErrMsg.RenderControl(writer); writer.Write(
"</td>"); writer.Write(
"</tr>"); writer.Write(
"</table>"); 
//table end writer.Write(txtContent.Text);
}
 catch (Exception ex) { 
this.lblErrMsg.Text = ex.Message.ToString(); } 
}
/// <summary> /// 8 th EVENT IN WEB PART /// Perform any final cleanup before the control is torn down. /// References to expensive resources such as database connections must be ///released in this phase. /// </summary> public override voidDispose(){
base.Dispose();}
/// <summary> /// 9 th EVENT IN WEB PART MANAGER/// Perform any final cleanup before the control is torn down. /// Control authors generally perform cleanup in Dispose and do not handle this event /// The webpart removed from memory of the server/// Generally webpart developer do not need access to this event because all /// the clean up should have been accomplish in dispose event /// </summary> /// <param name="e"></param>protected override void OnUnload(EventArgs e) { 
base.OnUnload(e); 
          }
     }
}

Build and Publish

--
Sudipto Roy
Asst. Manager - SharePoint (MCTS)