Tag: SharePoint

Create custom page layout in SharePoint Online

This post will explain about creating new page layout for SharePoint Online, same logic is  applicable for SharePoint 2013 and 2016.

Custom page layout can be used in SharePoint publishing site or Publishing feature enabled sites. Custom page layout can be used in SharePoint default master page or our custom master page,

SharePoint page layout sections

check my previous post about how to create custom master page for SharePoint
Navigate to SharePoint design manager and click Edit Page Layout link then click Create a page layout, in the popup enter new layout name and select master page and select existing SharePoint default content type or create new content type based on your requirement, you can find the create new content type link on the same popup.

SharePoint new page layout popup
Once the page layout is  created, open SharePoint Designer 2013 and open site on that. On the left side of SharePoint Designer select layout and you can find newly created layout files, there will be two files in same name one is HTML and another one is ASPX extension.
Check out the newly created page layout (HTML extension) and right click and select Edit File in Advanced Mode option.

SharePoint designer layouts

Once page layout opened then find out ContentPlaceHolder ID of “PlaceHolderMain”, clear all div elements inside the place holder and paste your page layout HTML or prepare your HTML inside.
If you created custom master page using HTML template conversion logic, then you have to cut center content(layout content) from master page and paste in this page layout.
Navigate to site home page and edit the page and select page tab, in that tab open page layout drop down and select our new layout.

And now your new page layout is ready..!!

Please feel free to let me know if you have any queries in the comment section, I’m happy to help you!!

Happy coding!!

Create custom master page for SharePoint Online

This post will explain about creating new master page for SharePoint Online, same logic is applicable for SharePoint 2013 and 2016.

There are various ways we can create custom master page for SharePoint, here I’m going to convert bootstrap HTML template to SharePoint mater page, hope you know that the bootstrap templates can change design based on the screen size, so these templates design are called responsive design.


You can download any HTML template from web; you will can zipped file then extract all files,

HTML Template files
Navigate to SharePoint admin center https://<tenant name>-admin.sharepoint.com

In the site collection tab click new and select Private or Public site collection

New Site Collection ButtonFill all the required details and select Publishing Portal template under Publishing tab

Create new publishing site
Once the site collection is created, open the site in the browser and SharePoint Designer 2013.
Once site is opened in the SharePoint Designer 2013, navigate to All files  _catalogs  masterpage

Master Page Directry
And copy and paste all the downloaded html template files like image, css, script folders and HTML file etc,.
Go back to the browser and click the gear button which is located on top right of the SharePoint page and select Design Manager.

Design Manager Link
On the design manager click edit master pages and click “Convert an HTML file to a SharePoint master page”

SharePoint Disign Manager Master page
On the dialog popup select you pasted HTML page and click Insert

now open SharePoint designer 2013 and find the newly created master page, you can find two files, in that edit the HTML extension and remove the center content(layout section contents) and find below highlighted code and cut and paste into the layout section.

layout section
Then publish the newly added master page in Design Manager or SharePoint design manager

Publishing Master Page
After publishing, go to the site settings and click master pages link under look on feel, select newly added master page in site master page drop down list and click OK to apply the new master page.

Select Master Page

And to finish it off  you will need to create a page layout and we are done!!

To create the page layout for the center content please click the below link and go ahead.

we have to create page layout for centre content which we removed from master page, check this URL for How to create SharePoint Page layout. 

Please feel free to let me know if you have any queries in the comments section,I’m happy to help you!!

Happy coding!!

Provider Hosted App For SharePoint Online

Create a new project in visual studio using “App for SharePoint” template, here I’m using visual studio 2015 version. After selected project can see a wizard

2016-01-24_10-20-52

Enter SharePoint online URL and select “Provider-Hosted” option next it will ask for user name and password, then wizard will automatically select “SharePoint Online” Option

2016-01-24_10-26-11

Next select ASP.Net MVC Web Application in the wizard

2016-01-24_10-29-44

Next leave by default selection of “Use Windows Azure Access Control Service (for SharePoint Cloud Apps)” then finish the wizard.

Create new razor view under home view folder

2016-01-24_12-02-36

Add new ActionResult in HomeController.cs, below code will retrieve list items from the “Shared Documents” and generates a DataTable. pass the DataTable to View.

 public ActionResult DocumentList()
{
DataTable dt = new DataTable();
var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
using (var clientcontext = spContext.CreateUserClientContextForSPHost())
{
List list = clientcontext.Web.GetList(spContext.SPHostUrl.ToString() + "Shared Documents");
clientcontext.Load(list);
CamlQuery cq = new CamlQuery();
ListItemCollection lic = list.GetItems(cq);
clientcontext.Load(lic, items => items.Take(15).Include(item => item["FileLeafRef"], item => item["Modified"],
item => item["Author"], item => item["FileRef"], item => item["File_x0020_Size"]));
clientcontext.ExecuteQuery();
dt.Columns.Add("File Name");
dt.Columns.Add("Modified", typeof(DateTime));
dt.Columns.Add("Author");
dt.Columns.Add("Size");

foreach (ListItem item in lic)
{
DataRow dr = dt.NewRow();
dr["File Name"] = "<a href=\"" + spContext.SPHostUrl.ToString().TrimEnd('/') + item["FileRef"]
+ "\">" + item["FileLeafRef"] + "</a>";
dr["Modified"] = item["Modified"];
dr["Author"] = ((FieldUserValue)item["Author"]).LookupValue;
dr["Size"] = item["File_x0020_Size"];
dt.Rows.Add(dr);
}
}

return View(dt);
}

Add below code to your new view, code will generate a HTML table using our ModelTable.

<div style="padding:5px 10px 3px 5px">
<table border="1" cellpadding="5" id="my-table">
<thead>
<tr>
@foreach (System.Data.DataColumn col in Model.Columns)
{
<th>@col.Caption</th>
}</tr>
</thead>
<tbody>
@foreach (System.Data.DataRow row in Model.Rows)
{
<tr>
@foreach (var cell in row.ItemArray)
{
<td>@Html.Raw(cell.ToString())</td>
}</tr>
}</tbody>
</table>
</div>

View name and action result name should be same else mention the view name in the return statement of action result.

In the AppManifest file select the permissions tab and Scope as list and permission as Read

2016-01-24_14-10-05

Run the project in visual studio using play button (F5), now can see SharePoint App Permission approval page, select Documents list then click “Trust it”

2016-01-24_14-13-02

After that SharePoint will redirect to our local hosted site, navigate to newly created view page. Page will display SharePoint list data.

2016-01-24_14-40-48

You can now compare your retrieved data with the actual SharePoint list.

2016-01-24_14-41-22