Sunday, 27 April 2014

Sharepoint FAQ

Sharepoint FAQ
Where do you deploy the additional files used in your webpart, like css or javascript files, and how do you use them in your WebPart?
Ans. You can deploy the css or javascript files in _layouts folder in SharePoint's 12 hive. To use them in your webpart, you need to first register them to your webpart page and then specify a virtual path for the file for e.g. _layouts\MyCSS.css See Code examples at Using External Javascript, CSS or Image File in a WebPart.
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.
How do make an existing non-publishing site Publishing?
Ans. You can simply activate the SharePoint Publishing Feature for the Site, you want to make publishing..
How do you deploy a User Control in SharePoint ?
Ans. You deploy your User Control either by a Custom webpart, which will simply load the control on the page or can use tools like SmartPart, which is again a webpart to load user control on the page. User Control can be deployed using a custom solution package for the webapplication or you can also the control in the webpart solution package so that it gets deployed in _controlstemplate folder.
Which is faster a WebPart or a User Control?
Ans. A WebPart renders faster than a User Control. A User Control in SharePoint is usually loaded by a webpart which adds an overhead. User Controls however, gives you an Interface to add controls and styles.
What SharePoint Databases are Created during the standard Install?
Ans. During standard install, the following databases are created :
SharePoint_AdminContent
SharePoint_Config
WWS_Search_SERVERNAME%_%GUID_3%
SharedServicesContent_%GUID_4%
SharedServices1_DB_%GUID_5%
SharedServices1_Search_DB_%
GUID_6%WSS_Content_%GUID_7%
While creating a Web part, which is the ideal location to Initialize my new controls?
Override the CreateChildControls method to include your new controls. You can control the exact rendering of your controls by calling the .Render method in the web parts Render method.
How do you return SharePoint List items using SharePoint web services?
Ans.
In order to retrieve list items from a SharePoint list through Web Services, you should use the lists.asmx web service by establishing a web reference in Visual Studio. The lists.asmx exposes the GetListItems method, which will allow the return of the full content of the list in an XML node. It will take parameters like the GUID of the name of the list you are querying against, the GUID of the view you are going to query, etc.
What are Customized and Uncustomized Files in SharePoint ?
Ans. There are two types of Pages in SharePoint; site pages (also known as content pages) and application pages.
Uncustomized :
When you create a new SharePoint site in a site collection, Windows SharePoint Services provisions instances of files into the content database that resides on the file system. That means if you create a new Site "xyz" of type Team Site(or Team sIte Definition), an instance of the Team Site Definition( Which resides on the File System), i.e. "xyz" gets created in the Content database. So, When ASP.NET receives a request for the file, it first finds the file in the content database. This entry in the content database tells ASP.NET that the file is actually based on a file on the file system and therefore, ASP.NET retrieves the source of the file on the file system when it constructs the page.
Customized :
A customized file is one in which the source of the file lives exclusively in the site collection's content database. This happens When you modify the file in any way through the SharePoint API, or by SharePoint Designer 2007,which uses the SharePoint API via RPC and Web service calls to change files in sites. So, When the file is requested, ASP.NET first finds the file in the content database. The entry in the database tells ASP.NET whether the file is customized or uncustomized. If it is customized, it contains the source of the file, which is used by ASP.NET in the page contraction phase.
If I wanted to restrict the deletion of the documents from a document library, how would I go about it?
Ans. You would create a event receiver for that list/library and implement the ItemDeleting method. Simply, set: properties.Cancel= true and display a friendly message using Properties.Message("How can u delete this... Its not your stuff!");
How would you remove a webapart from the WebPart gallery? Does it get removed with Webpart retraction?
Ans. No, Webpart does not get removed from the WebPart gallery on retraction. You can write a feature receiver on Featuredeactivating method to remove the empty webpart from the gallery.
How Do you bind a Drop-Down Listbox with a Column in SharePoint List ?
Ans.
Method 1 : You can get a datatable for all items in the list and add that table to a data set. Finally, specify the dataset table as datasource for dropdown listbox.
Method 2 : You can also use SPDatasource in your aspx or design page.
Page Layout in Sharepoint
http://weblogs.asp.net/jimjackson/archive/2007/11/05/create-a-new-page-layout-in-sharepoint-2007-feature-based.aspx
http://mysharepointwork.blogspot.com/2010/05/sharepoint-2007-moss-2007-interview.html.