Skip to content

Instantly share code, notes, and snippets.

@RyanABailey
RyanABailey / c#
Created November 10, 2015 06:02
Sitecore edit custom profile properties
Sitecore.Security.Accounts.User user = Sitecore.Security.Accounts.User.FromName("extranet\Ryan", true);
Sitecore.Security.UserProfile userProfile = user.Profile;
userProfile.SetCustomProperty("Title", "Mr"); // Set the custom property
userProfile.Save();
@RyanABailey
RyanABailey / C#
Created November 10, 2015 05:58
Sitecore assigning custom profile
Sitecore.Security.Accounts.User user = Sitecore.Security.Accounts.User.FromName("extranet\Ryan", true);
Sitecore.Security.UserProfile userProfile = user.Profile;
userProfile.SetPropertyValue("ProfileItemId", "{53DAD220-96B3-424C-9ABA-1D14740D7EF6}");
userProfile.Save();
@RyanABailey
RyanABailey / C#
Created November 9, 2015 01:16
Sitecore User Login
private static string Domain = "extranet";
public static bool Login(string email, string password)
{
var username = string.Format(@"{0}\{1}", Domain, email);
try
{
if (Sitecore.Security.Authentication.AuthenticationManager.Login(username, password))
{
@RyanABailey
RyanABailey / C#
Created November 9, 2015 01:11
Sitecore User Registration
private static string Domain = "extranet";
public static void RegisterUser(string firstName, string lastName, string email, string password)
{
var userName = string.Format(@"{0}\{1}", Domain, email);
try
{
if (!Sitecore.Security.Accounts.User.Exists(userName))
{
@RyanABailey
RyanABailey / Search Code
Created November 6, 2015 03:11
Lucene computed field search code
var index = ContentSearchManager.GetIndex("MySearchIndex");
using (var context = index.CreateSearchContext())
{
var searchResults = context.GetQueryable<SearchItem>().Where(x => x.ThumbnailUrl != null)
}
@RyanABailey
RyanABailey / Lucene Index XML
Created November 6, 2015 02:21
Sitecore Computed Field Index
<fieldMap type="Sitecore.ContentSearch.FieldMap, Sitecore.ContentSearch">
<fieldNames hint="raw:AddFieldByFieldName">
<field fieldName="title" storageType="YES" indexType="TOKENIZED" vectorType="NO" boost="1f" type="System.String"
settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider"
patch:after="field[last()]" />
</fieldNames>
</fieldMap>
<fields hint="raw:AddComputedIndexField">
<field fieldName="thumbnail" storageType="yes" indexType="untokenized"
@RyanABailey
RyanABailey / C#
Created November 6, 2015 02:12
Sitecore Computed Image Field
namespace My.Project.Web.ComputedFields
{
public class ComputedImageField : IComputedIndexField
{
/// <inheritdoc />
public string FieldName { get; set; }
/// <inheritdoc />
public string ReturnType { get; set; }
/// <inheritdoc />
@RyanABailey
RyanABailey / Basic
Created November 2, 2015 02:52
Search Index
<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="NewsSearch" type="Sitecore.ContentSearch.LuceneProvider.LuceneIndex, Sitecore.ContentSearch.LuceneProvider">
<param desc="name">$(id)</param>
<param desc="folder">$(id)</param>
@RyanABailey
RyanABailey / c#
Created October 12, 2015 09:28
Menu Item
/// <summary>
/// Menu Item
/// </summary>
public class MenuItem
{
/// <summary>
/// Gets or sets the link value.
/// </summary>
public string Link { get; set; }
@RyanABailey
RyanABailey / C#
Created September 23, 2015 00:56
Sitecore get media item
var item = Sitecore.Context.Database.GetItem(mediaItemID);
if (item.Paths.IsMediaItem)
{
var mediaItem = new MediaItem(item);
}