Surendra Sharma

Surendra Sharma

Search This Blog

Friday, May 24, 2019

Sitecore Smart Comment Analyzer using Microsoft Azure Text Analytics Service

Happy to share that I have created new Sitecore module "Smart Comment Analyzer using Microsoft Azure Text Analytics Service".

One can use this module on Product page or blog website pages to collect comments from visitors. These comments will be analyze for their sentiment score as positive or negative. All positive comments directly published on the website page while all the negative and abusive comments will be stored in external SQL database which further reviewed by Sitecore backend team for publish approval. 

Watch the video for more details. 


Tuesday, May 21, 2019

SUGCON INDIA 2019

Happy to share that I have attended my first SUGCON INDIA conference in Bengaluru on 16-17 May. I conducted session on "Search in Sitecore JSS".

I met with lots of Sitecore developers who join this from different parts of India. I come to know about some cool ideas and implementation from their sessions.

Glad to saw few ex-colleagues as well after a long time.

I was lucky to win the Apple PowerBeats Wireless headphone in one of the lucky draw.


Hope to join the next SUGCON India 2020.


You can download my presentation on "Search in Sitecore JSS" from here.
 
Sharing few clicks from the conference. I hope you will enjoy these clicks










Friday, May 10, 2019

Coveo for Sitecore Developers exam certificate

Happy to share that I successfully cleared Coveo for Sitecore Developers exam.

Coveo for Sitecore Developers
Coveo for Sitecore Developers

Tuesday, May 7, 2019

Microsoft Build 2019

Happy to share that we have attended very informative Microsoft Build 2019 Event on May 6, 2019 at Microsoft Office, Gurgaon.

Microsoft Build 2019
Microsoft Build 2019 at Microsoft Office, Gurgaon


Friday, April 19, 2019

Image tagging in Sitecore using Microsoft Computer Vision

Happy to share that I have created a module to add tags automatically to new or existing media library image item in Sitecore using Microsoft Computer Vision.

Watch the video for more details. 


Wednesday, April 3, 2019

Fixed : Sitecore multilist with search not showing data

In my Sitecore instance, I was not getting data in "Semantics" multilist with search field under "Tagging" section in Home item. By default this field should show atleast one value "Test tag".

Solution :-

Simply rebuild your master index. After that you should get data in multilist with search field.



Multilist with search
Multilist with search

Sunday, March 24, 2019

Code : Get any attribute value from HTML string in C#


If you have HTML string in C# and you want to get any particular value of any attribute then you can use below function which refer Regex to get its value.
In below program I am extraing “src” attribute value of HTML “img" tag.

Input string : <img alt="" src="/MediaCenter/PublishImages/DSC_0134.jpg" width="150" style="border:0px solid" />

Output : /MediaCenter/PublishImages/DSC_0134.jpg

Code:

using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace Rextester
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string s = "<img alt=\"\" src=\"/MediaCenter/PublishImages/DSC_0134.jpg\" width=\"150\" style=\"border:0px solid\" />";

            var srcs = GetSrcInHTMLImgString(s);
            Console.WriteLine(srcs[0]);//Output: /MediaCenter/PublishImages/DSC_0134.jpg
        }

        public static List<string> GetSrcInHTMLImgString(string htmlString)
        {
            List<string> srcs = new List<string>();
            string pattern = @"(?<=src="").*?(?="")";
           
            Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);
            MatchCollection matches = rgx.Matches(htmlString);

            for (int i = 0, l = matches.Count; i < l; i++)
            {
                string d = matches[i].Value;
                srcs.Add(d);
            }
            return srcs;
        }
    }
}

We can make this function more generic where we will pass any attribute name and get the value as

public static List<string> GetAttributeNameInHTMLString(string htmlString, string attributeName)
{
    List<string> attributeValues = new List<string>();
    string pattern = string.Format(@"(?<={0}="").*?(?="")", attributeName);

    Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);
    MatchCollection matches = rgx.Matches(htmlString);

    for (int i = 0, l = matches.Count; i < l; i++)
    {
        string d = matches[i].Value;
        attributeValues.Add(d);
    }
    return attributeValues;
}

Calling this function as

string s = "<img alt=\"\" src=\"/MediaCenter/PublishingImages/DSC_0134.jpg\" width=\"150\" style=\"border:0px solid\" />";

var widths = GetAttributeNameInHTMLString(s, "width");
Console.WriteLine(widths[0]);   //Output : 150

var styles = GetAttributeNameInHTMLString(s, "style");
Console.WriteLine(styles[0]);   //Output : border:0px solid

Its a small function but very handy. 

To test it, you can use C# online compiler “.NET Fiddle” instead of creating console application in Visual Studio. Many times I am using these online tools for quick testing. 

Let me know if you have any better idea to get attribute value from HTML string.