1. Document Library - how to set word template as default.
Main webpart base classes:
Why can't we use spcontext in event receivers?
We cannot use the SPContext.Current property into the event receivers, because the current context in event receivers is always equal to null.
Event Receiver remembers points:
IIS, Worker Process, AppPool
- By default, it is word template. We can change the template also.
- Go to document library-->settings-->form library settings-->Advanced settings
- In that “Template URL” option is there. We can give the path here.
2. Without using “CreateChildControl” is it possible to render a WebPart?
Yes, by using RenderControl method.
3. Can you create folders in custom list?
Yes. By default, Folder option is not available to the custom lists. For enabling it, go to the list settings-->Advanced settings-->select the “Display ‘New Folder” command on the New menu” option.
4. What is the maximum file size you can upload in SharePoint?
50MB- Central administrationàApplication managementàweb application general settings]
5. What are the file types we can’t upload to SharePoint site?
Central administrationàOperationsàBlocked file types under Security Configuration]
6. Content Retention:
We can configure “Information management policy settings on documents/content types to specify when they expire.
WebPart
Webparts:
Web Parts are reusable components that display content on Web pages in SharePoint 2010.
A fantastic new feature in SharePoint 2010 is that you can insert a Web Part in the text of one of the Rich Text Editor zone available in the new Wiki Page. (To add, remove, or rearrange the text zones, use the "Text Layout" menu in edit mode)
When you create a team site, the home page is a wiki page. You should be able to move the web parts by Editing (Page tab > Edit) then drag/dropping the web parts to where you'd like them to go. The wiki page won't really have web part zones, but instead you can choose a "Text Layout" to arrange your page as desired. Again you can drag and drop between the layout zones.
Also, when inserting a web part, the web part is added where your cursor is. To make sure you have it in the correct location, open the web part adder first (Edit Page > Insert Tab > Web Part), then click on the page where you want it to go, and then click Add in the web part adder.
Also, when inserting a web part, the web part is added where your cursor is. To make sure you have it in the correct location, open the web part adder first (Edit Page > Insert Tab > Web Part), then click on the page where you want it to go, and then click Add in the web part adder.
Remember points:
We can dropped webparts into anywhere inside the main content area, without having to put it into a WebPartZone (This is all happening behind-the-scenes through a dynamic zone that pushes Webparts into placeholders).
Difference Between .dwp and .webpart
- Dwp was the file extension used in version 2 of SharePoint and .webpart is a new extension used in version 3
- Version number on the xmlns attribute is different [2->2003, 3-> 2007]
- The main difference is that all properties passed to the web part are specified with a property element and a name attribute in version 3. Version 2 uses different element names for everything.
Reference:
Visual Webparts:
- The new important feature introduced in SharePoint on webparts is Visual webpart. It’s a combination of user control (.ascx) and assembly (.dll)
- Since a Visual Web Part loads a User Control (.ascx) from the SharePoint Root it needs access to run the ASP.NET method LoadControl and file system access to the ControlTemplates folder in the SharePoint Root – and this is not allowed by a Sandboxed Solution.
- Visual webpart cannot be deploying using sandbox solutions.
Visual sandboxed web part:
The Microsoft Visual Studio team has released the Visual Studio 2010 SharePoint Power Tools. These tools extend the existing SharePoint 2010 project templates and provide the Sandboxed Visual Web Part template that enables you to create Web Parts that can be deployed as sandboxed solutions. The use of these templates also enables designer support for designing the Web Parts.
Difference between asp.net webparts and SharePoint webparts?
ASP.NET Web Parts:
These Web Parts are built on top of the ASP.NET Web Part infrastructure. The ASP.NET-style Web Parts have a dependency on System.Web.dll and must inherit from the WebPart base class in the System.Web.UI.WebControls.WebParts namespace.
These Web Parts can be used in ASP.NET applications as well as in SharePoint Foundation, making them highly reusable.
SharePoint-based Web Parts:
These Web Parts have a dependency on Microsoft.SharePoint.dll and must inherit from the WebPart base class in the Microsoft.SharePoint.WebPartPages namespace.
These Web Parts can only be used in SharePoint Web sites.
Webpart life cycle:
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.
When the page is being rendered for the first time the method generally occurs after the OnLoad() event. In case of postback, it is called before the OnLoad() event. We can make use of EnsureChildControls() - It checks to see if the CreateChildControls method has yet been called, and if it has not, calls it.
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.
Webpart maintenance page
- A webpart which is causing a problem in a webpart page can be removed using this page. Basically, a Webpart Maintenance page provides the list of all webparts added in a particular page and options to close or remove these webparts.
- Use of it: Sometimes after adding a webpart to the page, we get an error page with some message. But in this error page we won’t get any SharePoint controls (like the SiteActions, Ribbon Menu etc.,), so we cannot edit the page and remove the webpart. Then we usually go to the edit form of the page (through page library) and then click on the 'Open Web Part Page in maintenance view' link, which opens the WebPart Maintenance page to remove the webpart which is causing the problem.
- Shortcut to open:
- Instead of going to the Edit Properties form of the page, we can easily open the WebPart Maintenance page by just adding the following query string to the page URL : ?contents=1
- So, if your page URL is 'http://rams/pages/default.aspx' then after appending the query string it should look like ' http://rams/pages/default.aspx?contents=1'
- Using this approach, we can open the webpart maintenance page for all the forms pages (like /pages/forms/allitems.aspx?contents=1). But it’s not safe to remove or add any webparts in these pages, as they may affect the normal functionality.
- Note: This approach works on both MOSS 2007 and SPS 2010.
Difference web parts visual web parts and traditional web part?
- The advantage of Web User Control is that you can use Visual Web Developer to design the web user control and in normal web parts all controls are created in the code itself i.e. on “CreateChildControls” method only.
- Adding Web Part properties is cumbersome for Visual Web Parts as compared to traditional Web Parts. As you develop Web Parts, many times you will want to expose their properties so that users and administrators can supply the values for those properties.
- Differences in Web Part Connections: This is easily achieved in a traditional Web Part because the logic code is contained in the Web Part itself.
- Differences when Extending a Web Part: You can extend the traditional Web Part by inheriting from the WebPart class. You can then reuse the base Web Part functionality and extend it as desired. Visual Web Parts cannot be extended. Because this Web Part is a wrapper around a user control, it just contains the code to load the user control; the bulk of the Web Part code resides in the code-behind file of the user control.
- Differences in Performance and Memory Footprint: Visual Web Parts have slightly larger memory footprints than code-only Web Parts. Visual Web Parts contain more parts (Web Part, user control) than traditional Web Parts.
- Refer the below msdn article to get a clear idea:
Main webpart base classes:
There are two base classes that a WebPart which is going to be consumed by SharePoint can inherit from, either the SharePoint WebPart Base class or the ASP.NET 2.0 WebPart base class. When inheriting from the SharePoint WebPart Base class your derived WebPart class will inherit from Microsoft.SharePoint.WebPartPages.WebPart. When inheriting from the ASP.NET 2.0 WebPart base class your derived WebPart class will inherit from System.Web.UI.WebControls.WebParts.WebPart. It is considered good practice to use the ASP.NET WebPart base class since the old base class is meant for backwards compatibility with previous version of SharePoint however there are four exceptions when it is better to leverage functionality from the SharePoint WebPart base class:
- Cross page connections
- Connections between Web Parts that are outside of a Web Part zone
- Client-side connections (Web Part Page Services Component)
- Data caching infrastructure.
Note: If you create a webpart in SharePoint 2010 by default it is inheriting from Asp.Net webpart base class.
A Web Part or Web Form Control on this Page cannot be displayed or imported. The type is not registered as safe.”
The reason for this error is if we modify default namespace into custom namespace, Visual Studio 2010 Package is not generating webpart file properly.
Make sure your webpart is added into Safe Control list in Web.config file.
Open your .webpart file in your visual studio - Make sure type element name has proper namespace & class name.
Open your .webpart file in your visual studio - Make sure type element name has proper namespace & class name.
When you made changes to default name space which is being generated by visual studio, you may not see updated namespace in type element. So make sure your webpart name space name & webpart class name placed correctly in type element's name attribute
Access http://server/_layouts/newdwp.aspx page and make sure webpart exist. If webpart not shown in the list, still your webpart name space/classname not matches to your safe control entry in web.config file.
Access http://server/_catalogs/wp/Forms/AllItems.aspx . By clicking on webpart opens webpart in webpart preview page.
Add Web Part inside a Master Page in SharePoint 2010?
I have added the webparts in masterpage successfully by referring the below post. Thanks, SharePoint King.
Note: we cannot add webpart zones to the master page.
Out of box webparts in SharePoint?
Below are my best references to get knowledge on out of box webparts.
Some of important OOB features are listed below:
CQWP:
CQWP:
- The Content Query Web Part is a very handy tool in SharePoint Standard and SharePoint Enterprise only i.e. not available at SharePoint Foundation.
- The CQWP is used to display the content by querying, filtering and sorting.
- The CQWP can fetch the data based on content types.
- By default, we can group and sort by only one field.
- Minimum designer level permissions required.
- CQWP is part of a bundle of features called “SharePoint Server Publishing Infrastructure”.
- The Content Query Web part cannot fetch data across site collections. If you really need it, you can take a look at the Lightning Conductor Web Part.
- Ref: http://sharepointlogics.com/2012/03/how-to-use-content-query-webpart-in.html
DVWP:
- A Data View Web part is a great way to display data with filtering, grouping, and user desired formatting.
- SharePoint Designer is required for developing DVWP.
- DVWP can fetch data from data sources other than lists like xml files.
- DVWP can fetch data from other site collection.
- DVWP can merge data from more than one list.
CQWP:
- The Content Editor Web Part (CEWP) allows you to add text, html, scripts or styles to a SharePoint page.
XSLT list Web part:
- Introduced in SP2010.
- In SharePoint 2010, all views in lists and libraries are XSLT list view web parts. This means that you can edit views from the browser or from SharePoint Designer 2010.
CSWP:
- Introduced in SP 2013.
- The Content Search Web Part (CSWP) is a Web Part that displays search results based on a search query.
Difference between user control and webpart?
Webparts are like user controls, user controls are added in code but webparts are added at runtime.
The advantage of Web User Control is that you can use Visual Web Developer to design the web user control and in normal web parts all controls are created in the code itself i.e. on “CreateChildControls” method only.
The advantage of Web User Control is that you can use Visual Web Developer to design the web user control and in normal web parts all controls are created in the code itself i.e. on “CreateChildControls” method only.
User Control
|
Web Part
|
User controls are based on Microsoft ASP.NET, and most developers are familiar with developing user controls. This improves productivity.
|
In general, developers are not familiar with creating child controls by writing the code from scratch.
|
User controls can be used with ASP.NET -based solutions. If you decide later to convert a project containing a user control to an ASP.NET -based solution, you should be able to use the control without making any changes.
|
Web Parts can be used in ASP.NET -based solutions only when the solution uses Web Parts pages.
|
The Visual Web Developer designer provides support for designing the UI by using drag-and-drop operations that gives the control a consistent look-and-feel, which results in faster development.
|
The controls in Web Parts must be added by using code.
|
User controls must be compiled before use, which adds to the time it takes to load the control.
|
Web Parts are precompiled and ready for use as soon as you need them.
|
Content Types
What is a Content type?
- Content types are reusable collection of metadata.
- Content types are available at site collections and site level. When you create a content type and add it to a site's content type collection, the new content type becomes available to any child site and also to the site where it was created.
- You never create a content type from scratch. Instead, you always select an existing content type as the basis for any new content type that you create.
- When you add a content type to list. Microsoft SharePoint foundation makes a local copy of site content type and adds the local copy to the list. This local instance is called "List Content type".
- To add a content type to a list, you must have List Administrator rights to that list.
Why content types
concept comes into the picture:
As per msdn why
content types, For
example, imagine a business situation in which you have three different types of
documents: expense reports, purchase orders, and invoices. All three types of
documents have some characteristics in common; for one thing, they are all
financial documents and contain data with values in currency. Yet each type of
document has its own data requirements, its own document template, and its own
workflow. One solution to this business problem is to create four content types.
The first content type, Financial Document, could encapsulate data requirements
that are common to all financial documents in the organization. The remaining
three, Expense Report, Purchase Order, and Invoice, could inherit common
elements from Financial Document. In addition, they could define characteristics
that are unique to each type, such as a particular set of metadata, a document
template to be used in creating a new item, and a specific workflow for
processing an item.
Scope of content
types:
- Content types are a site-scoped Feature. Content Type Features can be scoped only at a Site level.
- Typically Content Types and Site Columns are Site scoped; you can't deploy using features to a web.
Content types
inheritance:
- In Content types, Inheritance concept is introduces in SharePoint 2010.
- Inherited content types are not editable at the child level. Only way for editing is by using content type to list.
- Content Types only holds the reference of Site Columns or fields but does not contain columns or fields itself. As a result, columns can only be referenced in a Content Types so columns need to be created separately.
- If you remove any site column from site content type, then it will remove from site content type but the local copy/orphan column will not be deleted. Keep in mind that removing the site column from site content type is not the same as deleting it in the lists that use it already.
- Suppose if you modify the site column from the site content type that changes will affect to all its inherited content types.
- Reason: Site Columns are basically working as a template. It means whenever you attach any Site Columns to SharePoint list, a local copy of that site column (i.e. as list column) will be created. But interestingly SharePoint maintains the same field GUID for the above mentioned local copy or list column as well as for Site Column.
- So now you can understand how the SharePoint apply any changes in Site Column to its local copy. Yes, SharePoint uses that field GUID to track which list columns/local copy of site columns are "children" of a given site column and based on that the changes propagates.
Few basic points to
remember about content types:
- The collection that is returned by the AvailableContentTypes property is read-only. This is because the collection includes not only the content types that are defined on the current site but also those that are defined on sites above it in the site hierarchy.
- Content types that are created at the site level can be applied to child sites or lists.
- In Microsoft SharePoint Foundation 2010, every item has a content type assigned to it, either implicitly or explicitly.
- You can prevent users from making changes to specific content types in two ways, by using read-only content types and sealed content types. Each method has its advantages.
- Should have list administrator permissions to updates changes to the content types.
- The reference between Content Types and site Columns maintained using SPFieldLink (Microsoft.SharePoint.SPFieldLink).
- You cannot delete a content type from a list if that list contains items of that content type.
- Verify that the list can accept the content type that you have selected by calling the IsContentTypeAllowed(SPContentType) method.
- Make sure the list accepts content types.
- list.ContentTypesEnabled = true; Enable content types for the list by setting the value of the list’s ContentTypesEnabled property to true. In UI to enable content types go to list settings-->advanced settings--> Allow management of content type to "yes".
SPWeb.AvailableContentTypes
vs. SPWeb.ContentTypes
SPWeb.ContentTypes
- Gets the collection of content types for the Web site.
- The ContentTypes property returns only the content types that exist on the current Web site, not all content types in the current scope. Use the AvailableContentTypes property to return all content types in the current scope, including those of any parent Web sites. When you add a content type to this collection, you make it available to lists in the current Web site and in any child Web sites.
SPWeb.AvailableContentTypes
- Gets the collection of all content types that apply to the current scope, including those of the current Web site, as well as any parent Web sites.
- You can apply any content type that is returned in this collection to lists in the current Web site. However, you cannot add content types to the collection that is returned in this property. It is a read-only property. If you want to make a new content type available, you must add it to the collection that is returned by the ContentTypes property. That collection includes only the content types that exist in the current Web site.
Delete content
type
If you are
trying to remove a content type from the site collection where it is defined,
you must be sure that the GetUsages
method returns an empty list—that is, that the content type is not used on any
list and is not the parent of any child content type.
SPContentTypeUsage.GetUsages Method
- Returns a list of SPContentTypeUsage objects with information about where the specified content type is in use.
- This method returns a generic list of SPContentTypeUsage objects that contain information about each use of a content type in the site collection. If the content type is not used, the method returns an empty list (Count = 0).
- we can not delete the parent content type if already in use but we can delete the used site columns.
Associate a workflow
to the content type:
SPContentType.AddWorkflowAssociation to
associate workflow to the content type
In order
to associate workflow with a content type you have to change the
AssociationCategories element value in the workflow’s Elements.xml file to
ContentType.
Associate
workflow to the content type in feature+event receiver
Add the
event receiver to the content type:
EventRecievers
Event Receivers:
Event Receivers has taken places either synchronously or asynchronously. If the action has taken before code execution.
Synchronous events
· Occur before the event.
· Block the flow of code execution until your event handler completes.
· Provide you with the ability to cancel the events resulting in no after event (“…ed”) being fired.
Asynchronous events:
· Occur after the event.
· Do not block the flow of code execution in SharePoint
Note:-Event Handlers should be placed in GAC only.
New Features in SharePoint 2010:
- Another great improvement to event handlers in SharePoint 2010 is with the improvements to Visual Studio 2010, and what it takes to create them. Notice, when you add a new item into a Visual Studio project, three is an Event Receiver template you can choose from:
- Now can register an event to the site level or web level. In the feature xml file we have to use the “Scope” attribute to either “Web” [Web site] or “Site” [Site collection]. The default value will be site level. This is one of main feature introduced in SharePoint 2010.
- Another important one is the ListUrl attribute, which allows you to scope your receiver to a particular list by passing in the relative URL.
- Note: ListUrl works only if feature has Scope=”Web”. In case the feature has Scope=”Site”, event receiver is fired for every list and library, ListUrl is ignored.
- In SharePoint 2007, error messages are not user friendly in event receivers. Now in SharePoint 2010, can provide user friendly error messages by redirecting to our own custom application pages.
- By using below properties, we can do it:
properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;
properties.RedirectUrl = "/_layouts/EventReceiverProject1/CustomErrorPage.aspx?Error=" + errorMessage;
|
New Event Receivers on SharePoint 2010:
On List:
ListAdding(SPListEventProperties): This will be fired when a new list is getting created.
ListAdded(SPListEventProperties): This will be fired after a list is created in database.
ListDeleting(SPListEventProperties): This will be fired when a list is deleting.
ListDeleted(SPListEventProperties): This will be fired after a list is deleted from database.
On Web:
WebAdding(SPWebEventProperties): This will be fired before a new site is getting created.
WebProvisioned(SPWebEventProperties): This will be fired after web site is successfully created and provision processed successfully. This will work either in synchronous mode or asynchronous mode.
Note: A site is being provisioned and A site was provisioned-->Notice that now you are no longer depending on "feature stapling" to execute code on a site after it is provisioned. You can now just attach this web event. This is new concept introduced in SharePoint 2010.
DisableEventFiring() and EnableEventFiring():
One reason to prevent events from being raised is to avoid recursion. For example, if you have an ItemAdded event on a list and you write code within it to add an item, you can put that code in a DisableEventReceivers() ... EnableEventReceivers() block to avoid recursion.
When you add a new item, only the ItemAdding() event is raised. However, in cases where Explorer View is used, both the ItemAdding() and ItemUpdating events are raised. In such cases the ItemUpdating event always occurs after the ItemAdding() event occurs.
Difference between event receivers and workflows?
- Unlike Workflows, Event Receivers cannot be triggered manually. SharePoint event handlers run for a short period of time (generally seconds), while SharePoint workflows may run for a much longer time period (days, months, or even years).
- Workflows run asynchronously means we can trigger the workflows only when an item is created and when an item is modified but event receivers can work either synchronously and asynchronously.
- Workflows can start manually but Event Receivers cannot.
- Can cancel the operation in Workflows but in SharePoint 2010 we can cancel the event receivers also.
- We can create workflows either by using SharePoint designer or visual studio but we should create an event receivers using visual studio only.
- SharePoint event handlers are automatically initiated, while SharePoint workflows can be initiated either automatically or manually.
- There is no User Interface(UI) for the event receivers.
Reference:
Add an event receiver to the specific list programmatically?
Add an event receiver to the content type programmatically?
Add an event receiver to the content type using feature.xml file?
Best coding practice on event receivers?
The ItemUpdating event or the ItemUpdated event occurs two times when you enable the Require Check Out option for a document library in Windows SharePoint Services 3.0
How to Event Receivers with custom error page?
I have one requirement, i.e. is there is one list name “Student Marks” and fields has English, Hindi, Telugu, Total, AVG. Total=English+Hindi+Telugu. The total field should be update automatically if I update any of the language marks. But here the actual problem is if you are updating two fields at a time the ItemUpdating event fires 2times. But I don’t want to fire twice. How?
By using DiableEventFiring and EnableEventFiring methods we can prevent from event being raised 2 times. [Please refer on the above to get clear idea on those 2methods].
Why can't we use spcontext in event receivers?
We cannot use the SPContext.Current property into the event receivers, because the current context in event receivers is always equal to null.
Error Type: Error occurred in deployment step 'Recycle IIS Application Pool': The vssphost4.exe process was unable to start due to an unknown error.
The reason for cause of that issue is: Might be your opened solution debugging location is same as others opened solution debugging location. So, please close all the opened solutions and try again by opening your sol. That issue will not come this time.
I have one document library and I want to allow only specific extension files (like .doc, .pdf etc.) into that document library? How can I prevent it?
You need to prevent it before adding files into the document library for that we need write code in ItemAdding() event.
public override void ItemAdding(SPItemEventProperties properties)
{
base.ItemAdding(properties);
//if the list is equals to the PDF routing then only go inside...
if (properties.ListTitle.Equals(ConfigurationManager.AppSettings["PDF_Library_Name"], StringComparison.InvariantCultureIgnoreCase))
{
string fileUrl = properties.AfterUrl;
if (!string.IsNullOrEmpty(fileUrl))
{
fileUrl = fileUrl.ToLowerInvariant();
string fileExtension = Path.GetExtension(fileUrl);
if (!string.IsNullOrEmpty(fileExtension) && !fileExtension.Equals(".PDF", StringComparison.InvariantCultureIgnoreCase))
{
properties.Cancel = true;
properties.ErrorMessage = "Only PDF files are allowed for PDF signature routing. Please try again.";
}
}
}
}
|
- By default event receivers are asynchronous meaning that they run under the SharePoint timer service (OWSTIMER.exe). This means that the event receivers:
- Another important property you may want to set for each event you attach is the Sequence Number. The sequence number determines the order your event assemblies’ fire. This is especially important when you have created multiple assemblies that are all attached to the same Site, List or Content Type event.
- When you enable the Require Check Out option for a document library in Microsoft Windows SharePoint Services 3.0, the ItemUpdated event or the ItemUpdating event occurs two times. This occurs when the document library is updated. The same problem happens when you upload a document into a document library with a required column if this column is not filled in the document.
- Sol: DisableEventFiring() and EnableEventFiring() [Explained about these 2months below clearly.]
- My test is that itemadding and itemadded will fire after you click OK on the first window (the one you choose the document to upload) and before the second window appears;
- Itemupdating and itemupdated will fire after you click Save on the second window (the one you fill out Meta data).
- The default synchronization behavior is synchronous for before events and asynchronous for after events.
- You can tell SharePoint to just have the receiver work on the root site by using the RootWebOnly attribute on the <Receivers> node.
- Do not instantiate SPWeb, SPSite, SPList, or SPListItem objects within an event receiver. Event receivers that instantiate SPSite, SPWeb, SPList, or SPListItem objects instead of using the instances passed via the event properties can cause the problems: Check below on best practices on working Event Receivers.
- Debugging a SPEmailEventReceiver requires attaching the debugger to the OWSTIMER.EXE process. This is because the timer service fires the Incoming E-mail timer job, rather than the SharePoint web application.
Workflows
Workflows and types of workflows?
a. SharePoint 2010 workflows are based on Windows Workflow Foundation (WF). WF is part of .NET 3.5 Framework.
2. Sequential workflows?
a. In sequential workflows, the activities are placed in a logical order with an explicit start and an explicit end.
b. The activities are executed sequentially one after the other like a flow chart.
c. There is no going back to the previous step in a sequential workflow.
3. Difference between event receivers and workflows?
a. Unlike Workflows, Event Receivers cannot be triggered manually.
b. Event receivers will support both Before/After properties but workflows supports only after properties [Means u can’t able to perform “ing” operations].
c. SharePoint event handlers run for a short period of time (generally seconds), while SharePoint workflows may run for a much longer time period (days, months, or even years).
4. Difference between SharePoint designer workflows and custom workflows?
a. Only sequential workflows can be created in SharePoint Designer; state machine workflows cannot be created in SharePoint Designer.
b. Deployment and moving is easy in custom workflows when compared to SharePoint designer workflows.
c. Visual Studio can have code-behind.
d. Visual Studio generates a workflow template which can be easily be deployed, SharePoint Designer workflows are typically built against specific lists and sites.
e. Visual Studio allows for debugging!!
5. Why custom workflows can’t be deploying using sandbox solution?
a. In Workflow activity we have an .ACTIONS file. The .ACTIONS file will be stored in Physical Directory. But in Sandbox, we can't move any file to Physical location.
Name
|
Available for sandboxed solutions
|
Sequential Workflow
|
No. Programmatic workflows are not available for sandboxed solutions.
|
State Machine Workflow
|
No. Programmatic workflows are not available for sandboxed solutions.
|
Import Reusable Workflow
|
No. Programmatic workflows are not available for sandboxed solutions.
|
Import SharePoint Solution Package
|
Yes, if the items that is imported from the package are supported.
|
Workflow Association Form
|
No. Association forms include .aspx files and are not available for sandboxed solutions.
|
Workflow Initiation Form
|
No. Initiation forms include .aspx files and are not available for sandboxed solutions.
|
6. What type of issues you faced while developing workflows?
a. This view cannot be displayed because the number of lookup and workflow status columns it contains exceeds the threshold enforced by the administrator.
b. We will not get the metadata of document library when you assigned workflow. Workflow will immediately trigger once you upload doc to the doc library. So that’s the reason you can’t get the metadata of document library. So, I called my custom workflow manually in ItemAdded event.
7. How to attach workflows to the content types?
//To attach it for specific content type
<AssociationCategories>
ContentType;0x010100a945f312c7bd4a589d1489ca8307f24d</AssociationCategories>
//To attach it for all content types
<AssociationCategories>ContentType</AssociationCategories>
//To attach it for specific content type
<MetaData>
<AssociationCategories>
ContentType;0x010100a945f312c7bd4a589d1489ca8307f24d
;#ContentType;0x0101009a30bd7a9c18447e9b806af9c0931b9c
</AssociationCategories>
</MetaData>
|
8. How to attach workflows to the list and library?
<Workflow
Name="WorkflowProject1 - Workflow1"
Description="My SharePoint Workflow"
Id="d011cd8b-a95d-4d3e-bd53-e88345bbf5c4"
CodeBesideClass="WorkflowProject1.Workflow1.Workflow1"
CodeBesideAssembly="$assemblyname$">
<Categories/>
<MetaData>
<AssociationCategories>List</AssociationCategories>
<StatusPageUrl>_layouts/WrkStat.aspx</StatusPageUrl>
</MetaData>
</Workflow>
</Elements>
|
Remember points:
· Workflows run with “system account” by default.
· InfoPath forms cannot be created with Visual Studio. Previous versions of Visual Studio provided that capability but it was removed from the current 2010 version.
· Other debugging tips:
o Failed on Start usually means an error is happening in SharePoint before your workflow code spins up, such as not being able to find the workflow dll. Error Occurred usually means the workflow started and the error is somewhere in the code.
o Check the SharePoint ULS logs! – Fatal workflow errors might happen outside of your workflow, so they aren’t always visible in the debugger. Consult the logs to see if this is the case by opening the latest log and searching from the bottom up for “Workflow”. The logs are awesome resources that often get overlooked. Logs can be found in %Program Files%\Common Files\Microsoft Shared\web server extensions\12\LOGS.
· This view cannot be displayed because the number of lookup and workflow status columns it contains exceeds the threshold enforced by the administrator.
· Coded workflows cannot be deployed in a sandboxed solution.
· Only a Reusable workflow—not a List workflow or a Site workflow—can be saved as a sandboxed solution in SharePoint Designer.
· A workflow that is published as a Global Reusable workflow cannot be directly saved as a sandboxed solution in SharePoint Designer. However, you can copy it as a non-global workflow, which you can then save as a sandboxed solution. [ http://msdn.microsoft.com/en-us/library/gg615452.aspx ]
IIS, Worker Process, AppPool
What is IIS?
IIS (Internet Information Server) is one of the most powerful web servers from Microsoft Corporation that is used to host the Asp.Net web application. IIS has its own ASP.NET process engine to handle the ASP.NET request. So, when request comes from client to server, IIS takes the request and process it and send response back to the clients.
IIS means when request comes from client to the server a lot of operation is performed before sending response to the client. This is about how IIS process the request.
What is Worker Process?
Worker process (w3wp.exe) runs the ASP.NET application in IIS. This process is responsible to manage all the request and response that are coming from the client system. All the ASP.NET functionality runs under the scope of worker process. When request comes to the server from a client worker process is responsible to generate the request and response.
In single word, we can say worker process is the heart of ASP.NET web application runs on IIS.
What is Application Pool?
Simply to say about what is application pool is: A group of one or more URLs are served by a particular worker process or set of worker processes.
Application pool is the container of worker process. Application pools are used to separate sets of worker processes that share same configuration. Application pools enable a better security, reliability, and availability for any web application.
The worker process servers as the process boundary that separates each application pool so that when one worker process or application is having an issue or recycles, other applications or worker processes are not affected. This makes sure that a particular web application doesn’t impact other web application as they are configured into different application pool.
Application pool with multiple worker process is called “Web Garden”.
They provide a way for multiple sites to run on the same server but still have their own worker processes and identity.
Main Point to Remember:
• Isolation of Different Web Application.
• Individual worker process for different web application.
• More reliably web application.
• Better Performance.
• Individual worker process for different web application.
• More reliably web application.
• Better Performance.
How to find the application pool account for a web application?
Go to IIS settings (type inetmgr in command mode) and select the web application on left pane and click on the “Basic Settings” on the right pane.
Content database
What is mean by content database?
Ans: The content database is the repository for a lot of information such as web applications, site collections, sites, documents, lists, etc. By default SharePoint creates and associates only one content database with each web application created and all the site collections within a web application are also created within a single content database.
What is the max recommended SharePoint content database size?
MS recommends having content database not more the 100 GB for MOSS 2007 and 200GB for SP 2010.Use multiple content databases if necessary.
Note: A site collection should not exceed 100 GB [In sp2007] and 200GB [in sp2010] unless it is the only site collection in the database.
Why my Content Databases are named WSS_Content_<Guid>? The moment you create a Web Application, you will be asked to fill in details regarding your content database. By default, SharePoint will fill in this field for you with the following syntax: WSS_Content. If a content database with this name already exists, it will add a GUID to it.
Difference between configuration database and content database?
Can we restore the content database to the existing web application using central administration?
No. we can’t restore the content database to the existing web application but we can create a new content database using central administration. Only possible way is either by using PowerShell or stsadm.
How to get site collection list per content database?
How to add content database to the web application?
Through Central Admin:
http://www.etechplanet.com/blog/create-and-associate-multiple-content-databases-with-a-sharepoint-web-application.aspx [Best article]
Through STSADM:
STSADM.EXE -o addcontentdb -url http://Mywebapp:1010 -databasename WSS_Content_01
Through PowerShell:
New-SPContentDatabase -Name <ContentDbName> -WebApplication <WebApplicationName>
How to delete the content database of a web application?
Moving Site Collections between Content Databases:
Msdn comments: You can move site collections between content databases by using the Stsadm command-line tool or Windows PowerShell 2.0 commands. There is no graphical user interface for this task [http://technet.microsoft.com/en-us/library/cc825328.aspx ]
Rules:
· The source content database and destination content database must be located on the same instance of SQL Server.
· The source content database and destination content database must be attached to the same Web application.
If you have a content database that is getting too big, you can move one of more of its site collections to a different content database. Run the STSADM -o enumsites command described above and redirect the output to a file; e.g.: STSADM.EXE -o enumsites -url http://Mywebapp:1010 > sites.xml
Edit the output file using Notepad and delete the sites that you do not want to move; i.e. edit the sites.xml file so that it contains the list of site collections in a single content database that you want to move to another content database. You can then use a command like the following to move the site collections to another content database:
STSADM.EXE -o mergecontentdbs -url http:// Mywebapp:1010 -sourcedatabase <databasename> -destinationdatabase <databasename> -operation 3 -filename sites.xml
How can I check my content database size?
How can we attach more than one content database to a single web application?
Yes, but we cannot create/use more than one content database to single site collection.
How can we create a site collection in a specific Content Database?
Yes, but you can only do this by using PowerShell using the New-SPSite cmdlet. You can use the "-ContentDatabase" parameter to specify in which Content Database the site collection will be created. You will get an error saying the content database could not be found if the "-ContentDatabase" doesn’t exist.
How to monitor the content database size?
STSADM.EXE -o enumsites -url http://MyWebApplication:1010
Is it possible to have multiple content databases for a single Site Collection.?
No, a site collection cannot be split into different content databases. You can put different site collections into different content databases. Means One site collection = One content database and Multiple Site Collections = One Content Database
MasterPage
Masterpage provides layouts for set of pages. Master Pages are a template that other pages can inherit from to keep consistent functionality. The pages that inherit from Master Pages are referred to as content pages.
In SharePoint, when we add a new page from browser by going to Site Actions and select Create Page then there we will select the page layout and create the page. So we are selecting the page layout, it’s always binds to a master page. Whenever you change the default or custom master page, then the changes will be applied to all the page layouts by default. Because SharePoint won’t give direct master page URL or name anywhere. It will be ~masterurl/custom.master for custom master page and ~masterurl/default.master for the default master page.
Only one gallery exists per site collection and it is automatically populated when a new site collection is provisioned. Master pages cannot be shared across site collections, but a root site can share its master pages with the other sites in its site collection.
Note: Master Page directive at the top of the page: <%@Master language=”C#”%>
Content pages are the ASP.NET pages that implement a Master Page. Content pages are normal ASP.NET pages that contain an attribute which informs the compiler that the page should be merged with a Master Page. This attribute is part of the page directive tag and is called the MasterPageFile
What all are content placeholders in master pages?
Master page in SharePoint contains Content PlaceHolders. Content placeholders are areas of replaceable content on the master page. The tag is <asp:ContentPlaceHolder>. A master page may define many ContentPlaceHolder controls; a page does not have to implement a corresponding content control. There are contentplaceholders like PlaceHolderMain, which displays the main body of the page. PlaceHolderLeftNavBar, which contains the Quick Launch bar on the left side of the page, PlaceHolderTopNavBar, which contains the Top Navigation tabs at the top of the page, and PlaceHolderSearchArea, which contains the page’s search controls.
Master page in SharePoint contains Content PlaceHolders. Content placeholders are areas of replaceable content on the master page. The tag is <asp:ContentPlaceHolder>. A master page may define many ContentPlaceHolder controls; a page does not have to implement a corresponding content control. There are contentplaceholders like PlaceHolderMain, which displays the main body of the page. PlaceHolderLeftNavBar, which contains the Quick Launch bar on the left side of the page, PlaceHolderTopNavBar, which contains the Top Navigation tabs at the top of the page, and PlaceHolderSearchArea, which contains the page’s search controls.
Total count: 33
Visual reference to above mentioned Content Place Holders are
http://blogs.msdn.com/b/uksharepoint/archive/2009/05/21/sharepoint-master-page-content-place-holders.aspx
Visual reference to above mentioned Content Place Holders are
http://blogs.msdn.com/b/uksharepoint/archive/2009/05/21/sharepoint-master-page-content-place-holders.aspx
How to properly hide Content Placeholders in your SharePoint Masterpage?
Move the place holders which are not to show in asp panel and set the attribute visible to false.
Move the place holders which are not to show in asp panel and set the attribute visible to false.
SharePoint master pages have their own list/library called the Master Page Gallery .To access a SharePoint master page gallery goes to a SharePoint site collectionà site settings à master page gallery.
There are 3 main types of Master Pages in SharePoint
- Site Master Pages
- System Master Pages
- Application Master Pages
Site Master Pages are usually used in SharePoint publishing site definitions. These pages are used for the main .This is needed for publishing pages because the main page, of a site or sub site, usually has the publishing feature turned.
Site master pages are defined by ~masterurl/custom.master in the content page declaration.
Site master pages are defined by ~masterurl/custom.master in the content page declaration.
System master pages are used for most non-publishing sites and subpages (list or library) in publishing sites.
System master pages are defined by ~masterurl/default.master in the content page declaration.
System master pages are defined by ~masterurl/default.master in the content page declaration.
Application master pages are for all “Layout” pages. Layout pages are SharePoint administrative pages.
- v4.master - This is default master page
- Default. Master - this is used to support the 2007 user interface
- Minimal. Master
- Simple. Master- it is used for accessdenied.aspx, confirmation.aspx, error.aspx, login.aspx, reqacc.aspx, signout.aspx & webdeleted.aspx pages
V4.master: Default master page for most non-publishing sites in SharePoint 2010. It is also the default system master page in both SharePoint Foundation and SharePoint Server.
Default.master: Helpful from upgrading MOSS 2007 sites to SharePoint 2010 sites.
Minimal.master: page is best suited for pages with minimal branding and navigation. The minimal.master is used with search pages and Office web applications.
Simple.master: Master page used for error and login pages. It lives in the fi le system and is not available in the master page gallery.
MWSDefaultv4.master: Found in the master page gallery of meeting workspace sites.
Nightandday.master: page contains controls specialized for publishing web content management.
V4.master: Default team site master page. Provides ribbon bar and other UI changes.
Characteristics:
- Site actions are updated for 2010 and appear on left.
- Ribbon bar is available
Default.master: Sites upgraded from SharePoint 2007 use this unless they are changed to use a v4 version.
Characteristics:
- Site actions on right side and are same as SharePoint 2007 version
- No ribbon bar
Page layout dictates the overall look and feel of a web page. A page layout relies on a content type to determine the kind of content that can be stored on pages. Page layout contains field controls and web part.
Master pages and page layouts dictate the overall look and feel of your SharePoint site.
Differences are
Differences are
Master pages contain controls that are shared across multiple page layouts, such as navigation, search, or language-preference for multilingual sites. Page layouts contain field controls and Web Parts
Page layouts can be used by all page instances that are based on that page layout. Master pages can be used by all page instances in a site.
Site navigation provides the primary interface for site users to move around on the sites and pages on the site.
- Navigation controls on master pages
- Top link bar navigation
- Quick Launch navigation
- Breadcrumb navigation
- Tree view navigation
- Metadata navigation
- Navigation controls on page layouts
- Summary Links
- Table of Contents
- Content Query
- Navigation Web Parts
- Categories
- Site Aggregator
- Site in Category
- Tag Cloud
Ribbon Interface act as the UI enhancement in the product. It provides the commands to be executed in the form of Icons and tabs.
Select Empty Sharepoint template as a project template and select the module item for master page and css.
<Module Name="CustomMaster" Url="_catalogs/masterpage"> <File Path="CustomMaster\custommaster.master" Url="custommaster.master" Type="GhostableInLibrary" />
"Url="_catalogs/masterpage"" means this will be deployed to the master page library in SharePoint.
<Module Name="CustomMaster" Url="_catalogs/masterpage"> <File Path="CustomMaster\custommaster.master" Url="custommaster.master" Type="GhostableInLibrary" />
"Url="_catalogs/masterpage"" means this will be deployed to the master page library in SharePoint.
<Module Name="CustomCSS" Url="Style Library"><File Path="CustomCSS\DAVCSS.css" Url="CustomCSS/yourfile.css" Type="GhostableInLibrary" />
"Url="Style Library"" means this will be deployed to the style library in SharePoint.
Now add the following code in the feature receiver class file that contains above modules. Right click on the feature and click "Add Event Receiver"
public override void featureactivated(spfeaturereceiverproperties properties)
{
spsite currsite = (spsite)properties.feature.parent;
spweb curweb = currsite.rootweb;
uri masteruri = new uri(curweb.url + "/_catalogs/masterpage/custommaster.master");
curweb.masterurl = masteruri.absolutepath;
curweb.custommasterurl = masteruri.absolutepath;curweb.update();
}
This will apply the master page on activation of the feature.
"Url="Style Library"" means this will be deployed to the style library in SharePoint.
Now add the following code in the feature receiver class file that contains above modules. Right click on the feature and click "Add Event Receiver"
public override void featureactivated(spfeaturereceiverproperties properties)
{
spsite currsite = (spsite)properties.feature.parent;
spweb curweb = currsite.rootweb;
uri masteruri = new uri(curweb.url + "/_catalogs/masterpage/custommaster.master");
curweb.masterurl = masteruri.absolutepath;
curweb.custommasterurl = masteruri.absolutepath;curweb.update();
}
This will apply the master page on activation of the feature.
public override void featuredeactivating(spfeaturereceiverproperties properties)
{
spsite currsite = (spsite)properties.feature.parent;
spweb curweb = currsite.rootweb;
uri masteruri = new uri(curweb.url + "/_catalogs/masterpage/v4.master");
curweb.masterurl = masteruri.absolutepath;
curweb.custommasterurl = masteruri.absolutepath;
curweb.update();
}
{
spsite currsite = (spsite)properties.feature.parent;
spweb curweb = currsite.rootweb;
uri masteruri = new uri(curweb.url + "/_catalogs/masterpage/v4.master");
curweb.masterurl = masteruri.absolutepath;
curweb.custommasterurl = masteruri.absolutepath;
curweb.update();
}
3 steps involved to add the user control
Create and deploy user control
Register user control in the target
<%@ Register TagPrefix="MyUserControl" TagName="UserName" Src="~/_controltemplates/MyUserControl/MyUserControl.ascx" %>
Insert the user control wherever required.
<MyUserControl:UserName id="MyUserControl1" runat="server" />
Note: For webpart (Page.LoadControl method)
Use SharePoint designer. Register the namespace of the web part class using <% Register directive. Then use the specified tag prefix from "Register" directive to add the instance of Web part class. Web parts outside the web part zones are referred as static web parts and behave as normal web control.
Register the custom css file as below .
<SharePoint:CssRegistration name="<% $SPUrl:~SiteCollection/Style Library/Custom/styles.css %>" After="corev4.css" runat="server"/>
In CSS, we can wirtie the style for attaching image
background:url(../images/mainBG.jpg)
<SharePoint:CssRegistration name="<% $SPUrl:~SiteCollection/Style Library/Custom/styles.css %>" After="corev4.css" runat="server"/>
In CSS, we can wirtie the style for attaching image
background:url(../images/mainBG.jpg)
With the help of delegate control, we can take any OOB control of SharePoint and replace with our custom control without any modification in the SharePoint page. So that new custom control overrides the existing one.
So the delegate control provide one of the option to add control (either server control or user control) on a SharePoint page
For example : In master page SearchBox control is included as <SharePoint:DelegateControl runat="server" ControlId="SmallSearchInputBox" />
This delegate control object uses features to locate the control which is specified in ControlId.
We can overwrite the above delegate control by presenting the below code in Element file of feature <Control Id = "GlobalNavigation" Sequence="90" ControlSrc="~/_ControlTemplates/ucGlobNavDelegateControl.ascx" />
AdditionalPageHead, GlobalSiteLink(), GlobalSiteLink1, GlobalSiteLink2, SmallSearcgInputBox,
TopNavigationDataSource, PublicConsole, QuickLaunchDatasource
TopNavigationDataSource, PublicConsole, QuickLaunchDatasource
Searching through the main master page, Seattle.master, I’ve found these three new DelegateControls:
PromotedActions
SuiteBarBrandingDelegate
SuiteLinksDelegate
You can enable a Web Provisioned event receiver
using (SPWeb childSite = properties.Web)
{ using (SPWeb topSite = childSite.Site.RootWeb)
{ childSite.MasterUrl = topSite.MasterUrl;
childSite.CustomMasterUrl = topSite.CustomMasterUrl;
childSite.Update();
}
}
{ using (SPWeb topSite = childSite.Site.RootWeb)
{ childSite.MasterUrl = topSite.MasterUrl;
childSite.CustomMasterUrl = topSite.CustomMasterUrl;
childSite.Update();
}
}
Using the SharePoint web interface or SharePoint Designer 2010
Using a master page
Using a page layout
Using a Content Editor Web Part
This has to be done in the site definition file system. I don't think there is an Interface for that, but it can be via SPD though.
List Attribute Id= 116
Changes in topnavigation control in master page.
Ref: http://erikswenson.blogspot.in/2010/11/update-hide-first-tab-in-sp-2010.html
Ref: http://erikswenson.blogspot.in/2010/11/update-hide-first-tab-in-sp-2010.html
Master page and page layouts options missing in the left navigation in SharePoint designer 2010
Users having site ownership privileges are able to view the site's Collection Administration pages but will not see the link enabling them to make the appropriate settings change.
Site collection administrators will enable the “Enable SharePoint Designer “(Site ActionsàSiteSettingsàselect SharePoint designer settings under site collection Administration category)
Site collection administrators will enable the “Enable SharePoint Designer “(Site ActionsàSiteSettingsàselect SharePoint designer settings under site collection Administration category)
Conditionally renders the contents of the control to the current user only if the current user has permissions defined in the PermissionString.
<Sharepoint:SPSecurityTrimmedControl runat="server" PermissionsString="XYZ">
</Sharepoint:SPSecurityTrimmedControl>
</Sharepoint:SPSecurityTrimmedControl>
No comments:
Post a Comment