January 10, 2017

How to know C# version in Visual Studio

How can I know which C# version I am using in Visual Studio? We can know C# version by .Net framework .

1. C# 1.0  .NET 1.0

2. C# 1.2  .NET 1.1

3. C# 2.0  .NET 2.0

4. C# 3.0  .NET 3.5

5. C# 4.0  .NET 4

6. C# 5.0  .NET 4.5

7. C# 6.0  .NET 4.6

8. C# 7.0  .NET 4.6.2

To know .Net framework, Just right click on project, and select properties.

January 9, 2017

Website interaction data not reflecting in MongoDB

Recently I was stuck in one issue where my website interaction & contact data was not reflecting in MongoDB.  There are few points where you can do the fix for this.

1. Check you have added "<sc:VisitorIdentification ID="VisitorIdentification1" runat="server" />" this control or not on your layout.

2. In Sitecore.Analytics.Tracking.config file add your host name in value section.
<setting name="Analytics.ClusterName" value="YOUR HOST NAME" />

3. In Sitecore.Analytics.Tracking.config file add your host name in value section.
<setting name="Analytics.HostName" value="" />

January 8, 2017

Add profile image to Sitecore contact

You can use below method to associate image to Contact.

using (new SecurityDisabler())
      {
         
var image = "PASS MEDIA ITEM HERE"
;
         
MediaItem
getmediaItem = masterdb.GetItem(image.ID);
         
var
stream = getmediaItem.GetMediaStream();
         
var memoryStream = new MemoryStream
();
         
if (stream != null
) stream.CopyTo(memoryStream);
         
var pictureFacet = Tracker.Current.Contact.GetFacet<IContactPicture>("Picture"
);
          pictureFacet.Picture = memoryStream.ToArray();
          pictureFacet.MimeType = getmediaItem.MimeType;
      }

January 7, 2017

Show google map with multiple markers

You can use below code snippet to show Google map with multiple markers.

<style>
   
#map_wrapper
    {
       
height: 205px
;
       
width: 298px
;
    }

   
#map_canvas

    {
       
width: 100%
;
       
height: 100%
;
    }
    
input[type=file]
{
       
color:transparent
;
    }
</style
>

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_KEY_HERE&callback=initialize" async="async" defer="defer"></script>
<script>

   
function initialize() {
       
var
map;
       
var bounds = new
google.maps.LatLngBounds();
       
var
mapOptions = {
            mapTypeId:
'roadmap'

        };

        map =
new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
        map.setTilt(45);

       
var
markers = [
            [
'Marker1, Delhi'
, 24.524235, 77.165726],
            [
'Marker2, Delhi'
, 25.556695, 77.125543]
        ];

       
var
infoWindowContent = [
            [
'<div class="info">'
+
           
'<h3>DATA1</h3>'
+
           
'<p>PARA1</p>' + '</div>'
],
            [
'<div class="info">'
+
           
'<h3>DATA2</h3>'
+
           
'<p>PARA2</p>'
+
           
'</div>'
]
        ];

       
var infoWindow = new
google.maps.InfoWindow(), marker, i;

       
for
(i = 0; i < markers.length; i++) {
           
var position = new
google.maps.LatLng(markers[i][1], markers[i][2]);
            bounds.extend(position);
            marker =
new
google.maps.Marker({
                position: position,
                map: map,
                title: markers[i][0]
            });

            google.maps.event.addListener(marker,
'click', (function
(marker, i) {
               
return function
() {
                    infoWindow.setContent(infoWindowContent[i][0]);
                    infoWindow.open(map, marker);
                }
            })(marker, i));

            map.fitBounds(bounds);
        }

       
var boundsListener = google.maps.event.addListener((map), 'bounds_changed', function
(event) {
           
this
.setZoom(12);
            google.maps.event.removeListener(boundsListener);
        });

    }
</script
>

<div id="map_wrapper" class="map">

      <div id="map_canvas" class="mapping"></div>

</div>

 

January 6, 2017

Add image to media library programmatically in Sitecore

You can use below technique to add media file to media library in Sitecore.

var options = new Sitecore.Resources.Media.MediaCreatorOptions
   {
       AlternateText =
"",
       FileBased =
false
,
       IncludeExtensionInItemName =
false
,
       KeepExisting =
false
,
       Versioned =
false
,
       Destination =
"/sitecore/media library/Images/Contacts/"
+ ImageName,
       Database = Sitecore.Configuration.
Factory.GetDatabase("master"
)
   };

  
var
filename = Server.MapPath(Img.FileName);
  
var creator = new MediaCreator
();
  
var
mediaItem = creator.CreateFromStream(Img.PostedFile.InputStream, filename, options);

January 5, 2017

Read visitor profile details in Sitecore

We can read visitor’s personal details in Sitecore.

if (Sitecore.Analytics.Tracker.Current.Contact != null)
  {
    var personalFacet =    Tracker.Current.Contact.GetFacet<IContactPersonalInfo>("Personal"
);
    if (personalFacet != null
)
    {
       
if (personalFacet.FirstName != null
)
        firstName = personalFacet.FirstName;
    }
  }