Posts

Showing posts from February, 2014

Web Template in SharePoint 2010

When a user who has design rights customizes a website in the user interface (UI) or in a web-editing application, such as Microsoft SharePoint Designer, and then saves the website as a template, a web template is created. Web templates are stored in the Solutions Gallery of the top-level site in a site collection, where they become available for subsite creation on all websites in the site collection. A web template is persisted in the SharePoint database as a Microsoft SharePoint Foundation Solution, which is a file that has a .wsp extension. The .wsp file is stored in the Solutions Gallery of the site collection. The solution can also be deployed as a sandboxed solution. Web templates can be downloaded, edited, and redeployed as a sandboxed solution to other site collections. We recommend that you create a web template when your solution involves a custom site type. For more information, see  Deciding Between Custom Web Templates and Custom Site Definitions . Users cre...

Introduction to Collaborative Application Markup Language (CAML)

Image
Now that you've been putting a lot of data into your SharePoint server, what are the facilities available to you that allow you to query this data from SharePoint? There are many ways to pull data out of SharePoint. You can use the object model and get hold of the SPList object, and run a for/each over SPListItems. Of course, that isn't the smartest way to filter for data, though. Filtering via iteration can be extremely resource-expensive. You could use Search, even programmatically. You can do so by using the FullTextSqlQuery object as demonstrated in an article you can read at  http://blah.winsmarts.com/2008-2-SharePoint_Search_ranking_rules_and_running_it_programatically.aspx . While that will provide you with results quickly, it may or may not provide you with accurate results, and certainly has an external dependency on crawl schedules and algorithms. Given the nature of search, you also have limited control over the sorting mechanisms. The sorting is controlled gene...

Feature stapling

Feature stapling: Primary purpose of the feature stapling is to extend and customize existing site definitions. Usually these are used to provide some custom functionalities for the out of the box site definitions, but technique is definitely available also for the custom site definitions. Since it’s not supported to change the onet.xml file of site definitions after it has been used in environment, feature stapling is quite commonly used also to provide versioning for the already deployed custom site definitions. You can modify the stapling definitions to different site definitions also afterwards. It’s important to remember that stapled features are only activated on provisioning time, so if there’s any existing sites already provisioned, those won’t be affected automatically just by deploying new stapling definitions. Biggest downside with the feature stapling is that we can only extend the existing site definitions, we can’t provide new. This can be an issue for example when ...

Difference Between Site Template and Site Definition

Difference Between Site Template and Site Definition Before going into direct comparison, let me define both: Site Templates  : Are  snapshots of  sites at a point in time. When a user customizes a site from the UI or SPD, the custom template consists of the difference between the original state of the site (determined by its definition) and the state of the site or list when the custom template is generated. Custom templates remain tied to a particular site definition (for example, the site definition for SharePoint Web sites or Meeting Workspace Web sites), so that if the site definition is not present or is changed, the custom template cannot work. Site Definitions  : As the name implies, A Site definition is "core definition of a site”. Each site definition emerges through a combination of files that are placed in the 12 hive of WFE during installation of SharePoint. Site definition files include .xml, .aspx, .ascx, and .master page files, as well as docum...

SharePoint 2010 Content Query Web Part

Image
The story According to Microsoft the CQWP can be used to aggregate content from the following sources: a single list; a site and it’s subsites; an entire site collection; The story demistified The above mentioned is accurate...although not complete. Imagine this real world scenario. Contoso is a medium sized company with approx 25.000 documents. These documents reside in a single Site Collection and are spread over multiple document libraries. Off course we implemented a thorough information architecture and all documents are neatly classified in terms of content type and metadata. Now we have a business requirement: "I want a list of all contracts assigned to me." . Further, an architectural principle states only OOB functionality is allowed. And we are off.... Let's skip a couple of steps to the point, the CQWP is the way to go for this requirement (OOB it is... really... trust me... no you cannot use search because it cannot filter on [me] out o...

Update CreatedBy in SharePoint List item

using (var clientContext = new ClientContext(@"http://SP2010:8080/sites/TestSite/"))             {                 var web = clientContext.Web;                 var lst = web.Lists.GetByTitle("Projects");                 var newUser = clientContext.Web.EnsureUser("Narasimha, Prasad");                 var item = lst.GetItemById(896);                 clientContext.Load(newUser);                 item["Author"] = newUser;                 item["Editor"] = newUser;                 item.Update();                 clientContext.ExecuteQuery();                 Mes...

Groups DropDown in Grant Permissions Not Showing All Groups

We have SharePoint Server 2010. I go to Site Actions > Ste Permissions > Grant Permission. In the dropdown to "add users to a sharepont group" all of the groups in that site are not showing in the dropdown. For example, we have 16 groups and only 4 show in the dropdown. This is not consistent either. I can go to another site in another Site Collection that has the same number of groups and 8 out of the 16 will show in the dropdown. I can't find and pattern to the number or types of groups that are displayed in the dropdown. Solution: $web = Get-SPWeb "http://SP2010:8080/sites/TestSite/" $web.Groups | %{ $web.AssociatedGroups.Add($_) } $web.update() $web.dispose()

Convert dates in c#

DateTime? planDate;  planDate = column["Plan_Current"] == DBNull.Value ? (DateTime?)null : Convert.ToDateTime(column["Plan_Current"]); DateTime d = new DateTime();  d = Convert.ToDateTime(planDate);  string date = d.ToString("M/dd/yy");

Event Receiver and Custom Error Page

In this example I am going to show you how to use list item event receiver and how to redirect users to error page if something goes wrong. We have a list of contacts and we want to display an error message if the entered zip code doesn't a specific value. For this example I am using zip code 98052. If user enters a different ZIP code we display a custom error page. For custom error page we are going to create an application page. Start by creating a new Event Receiver project (I am using C# Event Receiver project). Because we are going to use an application page, select  Deploy as farm solution . In the Event Receiver wizard, select  List Item Events  for the type of the event receiver. Event source is going to be  Contacts  and we are interested in " An item is being added " event. Next, add an application page to the project and name it  CustomErrorPage.aspx . Let’s modify the application page and add a Label control to display the error message. Y...

Custom Error Message for Event Receiver

public override void ItemAdding(SPItemEventProperties properties) { try { base.ItemAdding(properties); EventFiringEnabled = false; if (!properties.AfterUrl.EndsWith("doc")) { properties.ErrorMessage = "You are allowed to updload only .doc files"; properties.Status = SPEventReceiverStatus.CancelWithError; properties.Cancel = true; } } catch (Exception ex) { properties.Status = SPEventReceiverStatus.CancelWithError; properties.ErrorMessage = ex.Message.ToString(); properties.Cancel = true; } }

Event receiver with two lists

<? xml version = "1.0" encoding = "utf-8" ?> <Elements xmlns = "http://schemas.microsoft.com/sharepoint/" > <Receivers ListUrl = "Lists/MARFlowsheet" > <Receiver> <Name> EventReceiver1ItemAdding </Name> <Type> ItemAdding </Type> <Assembly> $SharePoint.Project.AssemblyFullName$ </Assembly> <Class> FlowSheetInmateIDCheck.EventReceiver1.EventReceiver1 </Class> <SequenceNumber> 10000 </SequenceNumber> </Receiver> </Receivers> <Receivers ListUrl = "Lists/Flowsheet" > <Receiver> <Name> EventReceiver2ItemAdding </Name> <Type> ItemAdding </Type> <Assembly> $SharePoint.Project.AssemblyFullName$ </Assembly> <Class> FlowSheetInmateIDCheck.EventReceiver1.EventReceiver1 </Class> <S...

Difference between Visual Webpart and traditional webpart

1. Visual Web Parts have slightly larger memory footprints than code-only Web Parts. 2. Visual Web Parts contain more parts (Web Part, user control) than traditional Web Parts.  Thus, loading a Visual Web Part takes longer than a traditional Web Part, resulting in poorer performance. 3. 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 4. Visual Web Parts can be deployed only as farm solutions because they deploy the user controls to the SharePoint root folder. Traditional Web Parts can be deployed as sandboxed solutions. 5. Visual Web Parts are similar to user controls in that you can simply drag and drop items from the Toolbox onto your custom controls to create a Web Part UI. You also get the code-behind file where you implement the UI logic. Technically, the SharePoint 2010 Visual Web Part is an ASCX web user control that is hoste...

The following URL is not valid in Info Path form publishing

Image
Problem: I have created a leave form and tried to publish it to my "Leave Form" library located at http://sharepoint:2222/sites/bat/leave form. But Infopath 2010 generates an error "The following URL is not valid http://....". when i  enter this URL  for infopath form services site. Figure: Infopath form Services URL  Figure: Infopath form publishing error After trying couple of times the following workaround solved my problem. The way i solved it:  I have  created a  Site Collection  named Marketing (for example) on my  Web Application  at the root Which is  under http://servername:2222/ but not under http://servername:2222/sites/ . Figure: Create Site collection at the root of web application  And this has solved my problem.Now i can publish my form at http://servername:2222/sites/sitename/leave form library. Figure: Infopath form publishing successfully That's all.