Skip to content

Instantly share code, notes, and snippets.

// The SecurityDisabler overrides the current security model, allowing you
// to access the item without any security. It's like the user being an administrator
using (new Sitecore.SecurityModel.SecurityDisabler())
{
// Get the master database
Sitecore.Data.Database master = Sitecore.Data.Database.GetDatabase("master");
// Get the template to base the new item on
Items.TemplateItem template = master.GetItem("/sitecore/templates/Sample/Sample Item");
// Get the place in the site tree where the new item must be inserted
@DaveGoosem
DaveGoosem / dropDownPopulate.cs
Created June 16, 2013 23:55
Populate Drop Down List with Sitecore data template items
//IncidentCategoryList is the list control
//In this example we are only showing child items of the datasourced item which are using a specific Sitecore template named 'IncidentCategory'
foreach (
var categoryDropDownItem in
DataSourceItem(IncidentCategoryItemId).Children.Where(z => z.TemplateName == "IncidentCategory"))
{
IncidentCategoryList.Add(categoryDropDownItem.DisplayName);
}
@DaveGoosem
DaveGoosem / getPublishDate.cs
Created June 13, 2013 12:12
Get Sitecore item 'last published' value AKA 'updated'
public Item item;
public String PublishDate()
{
DateTime postDate = Context.Item.Statistics.Updated;
return postDate != null ? postDate.ToString("MMMM dd yyyy H:mm:ss tt") : String.Empty;
}
@DaveGoosem
DaveGoosem / AdaptiveDesign.css
Created May 26, 2013 12:24
Adaptive Design - Media Queries
/* Plonk as many of these as you need for each device/context and they will be
applied when the media query defined is met.*/
@media screen and (max-width: 320px)
{
/* all styles for this query size go here. */
/*
for mobile, get of as many floats as possible sot hey sit on top
of eachother down the page nicely.
@DaveGoosem
DaveGoosem / sessionTimeout.xml
Created May 17, 2013 02:09
To set the session timeout value for admin Sitecore users.
<!--
Session expiration for the Sitecore Client.
When managing Client sessions, Sitecore keeps track of every user logged in to the system and assigns a Sitecore user ticket to every user accessing a Sitecore Client application. Sitecore Client user session is not limited in time and is kept alive until the browser is opened.
However, if after 8 hours of the current user inactivity another user logs in and the current Sitecore license used has a concurrent number of users limitation – a newly logged in user may take the currently logged in user’s license slot. Current user will be redirected to the login page when trying to use any Sitecore Client application if there are no more available license slots left for him to automatically re-login to the system.
If 8 hours inactivity period is too long and needs to be changed, the following workaround can be applied:
Copy the Sitecore.Support.323551.dll assembly to the \bin folder.
http://sdn.sitecore.net/upload/faq/session%20expiration/sitecore.support.323551.
@DaveGoosem
DaveGoosem / changeDBowner.sql
Created May 16, 2013 00:17
Forcibly changes the owner of a Databse
--replace <newOwner> with DB user
exec sp_changedbowner '<newOwner>'
@DaveGoosem
DaveGoosem / userUpdate.sql
Created May 16, 2013 00:15
User Update Query when restoring backups
--it uses It uses the <user>, <login> in that order
EXEC sp_change_users_login 'Update_One', '<user>' , '<login>'
@DaveGoosem
DaveGoosem / clearSitecoreCache.cs
Created May 14, 2013 03:17
Clearing Sitecore Cache
Database db = new Database("web");
if (ID.IsID(id))
{
ID itemID = new ID(id);
//clear data cache
db.Caches.DataCache.RemoveItemInformation(itemID);
//clear item cache
db.Caches.ItemCache.RemoveItem(itemID);
@DaveGoosem
DaveGoosem / KBListingML.ascx
Created May 10, 2013 05:54
Example Sitecore control using datasources and Multilists Note: Multilists need to use Sitecore Item IDs find items.
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="KnowledgeBaseListing.ascx.cs" Inherits="DigiconNew.layouts.Sublayouts.Controls.KnowledgeBaseListing" %>
<% foreach (var kbcategory in KBCategories)
{
%>
<div class="article">
<div class="article-title">
<h3>
<a href='<%= GetURL(kbcategory) %>'><%= kbcategory["Article Title"]%></a>
</h3>
@DaveGoosem
DaveGoosem / encodeURI.js
Created May 9, 2013 01:20
Encode script for XSS testing
/*
Use the encodeURIComponent to allow you to switch out all characters to their encoded
values. You can then attempt to inject into forms using the encoded values.
Example Below:
*/
//in Web Tools (F12 in chrome), in the console, enter something like this:
encodeURIComponent('<script>alert("please soemthing")</script>')
//will return value like this which you can copy/paste into input fields on site to test