Skip to content

Instantly share code, notes, and snippets.

@RyanABailey
RyanABailey / C# code behind
Created August 18, 2014 02:25
Custom web party property
private DisplayEnum _display = DisplayEnum.TitleAndBorder;
[WebBrowsable(true), Personalizable(PersonalizationScope.Shared)]
public DisplayEnum Display
{
get { return _display; }
set { _display = value; }
}
@RyanABailey
RyanABailey / c#
Created September 3, 2014 07:45
SharePoint 2013 access image URL for custom image field on a page
var image = (ImageFieldValue)SPContext.Current.File.Item["ImageFieldName"];
if (image != null)
{
string imageUrl = image.ImageUrl;
}
@RyanABailey
RyanABailey / JS
Created September 10, 2014 07:52
current page is checked out to the current user
var isCheckedOut = false;
if (typeof (PageState) != "undefined" && PageState) {
isCheckedOut = PageState.ItemIsCheckedOutToCurrentUser == "1";
}
@RyanABailey
RyanABailey / html
Created September 12, 2014 03:40
angularJs run code after page load
<div id="myDiv" ng-controller="MyCtrl">
</div>
@RyanABailey
RyanABailey / C# Sort
Created October 23, 2014 06:42
c# custom list sort
var menuItems = new List<MenuItem>();
// add items
menuItems.sort();
@RyanABailey
RyanABailey / search.config
Created October 30, 2014 03:24
Sitecore search config
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<contentSearch>
<configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch">
<indexes hint="list:AddIndex">
<!-- Change this to Sitecore.ContentSearch.LuceneProvider.SwitchOnRebuildLuceneIndex, Sitecore.ContentSearch.LuceneProvider if you would like indexes to be
built in a temporary directory i.e. while rebuilding is happening, your old indexes work like normal until the rebuild is finished. -->
<index id="content_index" type="Sitecore.ContentSearch.LuceneProvider.LuceneIndex, Sitecore.ContentSearch.LuceneProvider">
<param desc="name">$(id)</param>
<param desc="folder">$(id)</param>
@RyanABailey
RyanABailey / MyResultItem
Created October 30, 2014 03:43
SearchResultItem
public class MyResultItem : SearchResultItem
{
[IndexField("Heading")]
public string PageHeading { get; set; }
[IndexField("Content")]
public string PageContent { get; set; }
}
@RyanABailey
RyanABailey / search.cs
Created October 30, 2014 03:47
sitecore search
var searchResults = new List<SearchResult>();
string searchTerm = Request.QueryString["term"];
var index = ContentSearchManager.GetIndex("content_index");
using (var context = index.CreateSearchContext())
{
var results = context.GetQueryable<MyResultItem>().Where(resultItem => resultItem.PageHeading.Like(searchTerm) || resultItem.PageContent.Contains(searchTerm)).GetResults();
foreach (var result in results)
{
@RyanABailey
RyanABailey / code behind
Created October 30, 2014 05:07
linkfield to url
/// <summary>
/// Get the URL for a given sitecore linkfield
/// </summary>
/// <param name="lf">sitecore linkfield</param>
/// <returns>web URL</returns>
public static string GetLinkFieldURL(LinkField lf)
{
switch (lf.LinkType.ToLower())
{
case "internal":
@RyanABailey
RyanABailey / code behind
Created October 30, 2014 05:12
sitecore get image url
/// <summary>
/// get image url from sitecore imagefield
/// </summary>
/// <param name="field">imagefield</param>
/// <returns>image url</returns>
public static string GetImageURL(ImageField field)
{
string imageURL = string.Empty;
if (field != null && field.MediaItem != null)
{