October 30, 2015

How to perform a null check on a dynamic object

If you want to check dynamic variable's value you can use "ReferenceEquals" in C#.

if (ReferenceEquals(null, <Dynamic Variable>)
   // To do something

October 29, 2015

Add context menu in Sitecore

Objective of this post is to know how we can add context menu in sitecore.
At first instance, it looks very difficult process but it is not.

What you need to do if you want to add a conetext menu in sitecore instance.
Just traverse to this location "/sitecore/content/Applications/Content Editor/Context Menues/Default" in core database
and add your item here as in below picture.

October 28, 2015

Generate Brightcove API access token

I have written one method here to generate access token for Brightcove API.
Once you have Brightcove API access token, you can work on API.

private string CLIENT_ID = "<Put here client ID>";
private string CLIENT_SECRET = "<Put here client secret>";
private string ACCESS_TOKEN = String.Empty;
private RestClient _client;

protected void Page_Load(object sender, EventArgs e)
        ACCESS_TOKEN = GetAccessToken();

private string GetAccessToken()
        _client = new RestClient("https://oauth.brightcove.com");

        string authInfo = CLIENT_ID + ":" + CLIENT_SECRET;
        authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));

        RestRequest request = new RestRequest(Method.POST)
            Resource = "/v3/access_token",
            RequestFormat = DataFormat.Json,

        request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
        request.AddHeader("Authorization", "Basic " + authInfo);
        request.AddParameter("grant_type", "client_credentials");

        var response = _client.Execute(request) as RestResponse;
        JObject joResponse = JObject.Parse(response.Content.ToString());
        return (string)joResponse["access_token"];   

That's It.
Enjoy Learning

October 22, 2015

JSON editor online

If you have JSON output as string and you want to format it; you can do it online. This is nice tool to work with JSON output.
Use below url to format JSON string.


Just paste your JSON string in text box and click on run button you will see formatted JSON output.

That’s It.
Enjoy Learning

October 14, 2015

Upload Video to Sitecore Instance

public static void UploadToSitecore(Stream stream,string filename,string filepath)      
MediaCreatorOptions options = new Sitecore.Resources.Media.MediaCreatorOptions
    options.Database = Sitecore.Configuration.
    options.Language = Sitecore.Globalization.
    options.Versioned = Sitecore.Configuration.
    options.Destination = filepath;      
    options.FileBased = Sitecore.Configuration.
MediaCreator creator = new Sitecore.Resources.Media.MediaCreator
sample = creator.CreateFromStream(stream, filename, options);      

That’s It
Enjoy Learning

October 13, 2015

Get Dictionary Item value in Sitecore

Sitecore Dictionary item is very helpful  to maintain key-value pair information in Sitecore instance.Below function to get dictionary item value by item name. You just need to pass dictionary path and item name

public string GetDictionaryItem(<Pass here dictionary item name>)      
Database database = Sitecore.Configuration.Factory.GetDatabase(“master”);      
Item currentItem = database1.GetItem(String.Concat(<dictionary path>, (<Pass here dictionary item name>));      
string val = String.Empty;      
if (currentItem != null)      
        val = currentItem[
return val;      

That’s It.
Enjoy Learning.