Pages

Tuesday, August 19, 2014

SharePoint site content doesn’t show in search results in SharePoint 2013

Problem

A site collection (Its a Search Center site collection. We had some lists and list items under the site collection) and its contents are not listed in search results; though I have added site url as a content source in search service application.

Solution

Go to Site setting and Click on Search and offline availability.

image 

Then select the radio button under “Allow this site to appear in search results?”

image Run the crawler again and you content will be listed under search results.

Solution Background

By default “Yes” option will be selected if we create a site collection with a template other than the “Basic Search Center”. 

Monday, August 18, 2014

Add items to SharePoint list declaratively through Visual Studio

Problem

We had to add couple items to SharePoint list declaratively. So that when we deploy the solution, SharePoint list and the default items will be provisioned in SharePoint site.

Solution

Step 01:

Add a SharePoint list to Visual Studio.

Step 02:

Open the Elements.xml file of list instance.

image

So you will see something like this.

image

Step 03:

Add the data.

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  3.   <ListInstance Title="List1"
  4.                 OnQuickLaunch="TRUE"
  5.                 TemplateType="10000"
  6.                 Url="Lists/List1"
  7.                 Description="My List Instance">
  8.     <Data>
  9.       <Rows>
  10.         <Row>
  11.           <Field Name="Title">Item 001</Field>
  12.         </Row>
  13.         <Row>
  14.           <Field Name="Title">Item 002</Field>
  15.         </Row>
  16.       </Rows>
  17.     </Data>
  18.   </ListInstance>
  19. </Elements>

Here the Name in the field will be column name.

Conclusion

Right click and deploy. Then open the list in the browser and you can see the items.

image You can download the basic sample solution from the below link.

https://drive.google.com/file/d/0ByEnOE8DAdvhVjB4RVkxUk9CcWM/edit?usp=sharing

Thursday, August 14, 2014

Add lookup column through Visual Studio UI

Introduction

In my last blog post I described “How to add items to Choice field through Visual Studio 2012/2013”; in this blog post I will show “How to add lookup column through Visual Studio user interface”.

Solution

Step 01:

Create Column through Visual Studio with the type Lookup.

image

Step 02:

Exact Type in properties by clicking the + sign.

image

Description for red numbers from the screenshot.

1. The reference list (lookup list) url where you have your lookup column. – Mandatory

2. The lookup  column which you have to link to. – Optional. Incase you didn’t mention the field the title field will be shown.

Conclusion

Deploy the solution and after adding the data to the reference list; you can see data in your lookup column field.

Wednesday, August 13, 2014

How to add items to Choice field through Visual Studio 2012/2013

Introduction

Unlike in Visual Studio 2010, we can create columns via user interface in Visual Studio 2012 and Visual Studio 2013.

We may need to create column type as choice field or multiple choice and can add default values, so users can select the values from the items which we add. I will show how to add default items for choice field and multiple choice field.

Solution 

Step 01:

Open the list and select Choice type.

image Step 02:

Exact Type in properties and click “…” near items. A window will open and you can add the items which you want to show when you deploy the list.

image

 

Conclusion

You can see the values after deploying the list.

image

Wednesday, August 6, 2014

Create Site Pages through Visual Studio for SharePoint 2013 and SharePoint Online

Introduction

Recently I had to tell one of friends how to create Site pages in SharePoint 2013 with Visual Studio. So I had to come up with a easiest way to describe. Here is it.

Solution

I will be adding a application page and making it as the site page.

Step 01: Add a Application Page

Right click on the project and and a new item (Add –> New Item); there select Application Page.

Step 02: Add a module for site page

Right click on the project and and a new item (Add –> New Item); there select Module.

Step 03: Drop application page inside module

Drag and drop the application inside the module. So your module will look something like this.

image 

Step 04: Remove the Code behind file

Our intension is to add webpart zone inside the application page and no need of code behind, So we will delete the file with the extension “.aspx.cs”. Now the module will be look something as below.

imageStep 05: Remove code behind reference from aspx page

Go to aspx page and in our case its “ApplicationPage1.aspx” and remove the line

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ApplicationPage1.aspx.cs" Inherits="SitePages.Layouts.SitePages.ApplicationPage1" DynamicMasterPageFile="~masterurl/default.master" %>

Here the master page also will get removed. So we have to add the reference to the master page. Add the below code at the top of the page.

  1. <%@ Page Language="C#" MasterPageFile="~masterurl/default.master" Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage,Microsoft.SharePoint,Version=15.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>

Step 06: Remove project assemble.

Remove the below line which refer the the project. If not this is will throw an error when we try to deploy in SharePoint online.

  1. <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>

Step 07: Add webpart zone

Now add webpart zone into PlaceHolderMain.

  1. <asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
  2. <WebPartPages:WebPartZone ID="WebPartZoneSearch" runat="server" Title="Webpart zone">
  3.                         <ZoneTemplate>
  4.                         </ZoneTemplate>
  5.                     </WebPartPages:WebPartZone>
  6. </asp:Content>

Once you add Webpart Zone you have to import necessary assembly. Add below register tag on the page.

  1. <%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

Step 08: Deploy the solution.

Now deploy the solution and you can go to your site page through the url in the module.

image

So the url will http://<SiteUrl>/Module1/ApplicationPage1.aspx

Conclusion

Now your site page is deployed and you can see the webpart zone in the edit mode also.

image

You can download the code from here.

https://drive.google.com/file/d/0ByEnOE8DAdvhZW5QbktFRzR3bnM/view?usp=sharing