Blog Archives

// Build 2016 – The Future of C# (CH9)

Since Roslyn shipped last year we’ve been hard at work building on it to improve tooling, add new language features and enhance Roslyn itself. In this session Dustin and Mads will play with fire, showing early versions of new C# 7 language features such as tuples and pattern matching, new editor features like code style and source generators, and much more.

The news about 7.0 version are:

  • Binary Literals
  • Local Functions
  • Tuple
  • Pattern Matching
  • Ref Locals and Ref Returns
  • Records

Take a look at the presentation



SEO – Change Meta Tags Dynamically in SharePoint or – (JavaScript & C#) – Google Crawlers


Meta tags are a great way for webmasters to provide search engines with information about their sites. They can be used to provide information to all sorts of clients, and each system processes.

Meta tags are added to the <head> section of your HTML page and you can add them dynamically use JavaScript when page load or using c#:

The following examples explain how can you add it on your header Page:

1. Use c#

public static void ApplyTagsCSharp(string xtitle, string xkeywords, 
string xdescription, Page page)
            page.Title = xtitle;
            ContentPlaceHolder contentPlaceHolder = 
            (delegate(System.Web.UI.HtmlTextWriter writer,
            System.Web.UI.Control Container)

            ////Add Keywords Meta Tag
            HtmlMeta keywords = new HtmlMeta();
            keywords.HttpEquiv = "keywords";
            keywords.Name = "keywords";
            keywords.Content = xkeywords;

            //Add Description Meta Tag
            HtmlMeta description = new HtmlMeta();
            description.HttpEquiv = "description";
            description.Name = "description";
            description.Content = xdescription;

2. Use JavaScript with ClientScriptManager

public static void ApplyTagsJS(string title, string keywords, 
string description, string author, ClientScriptManager csx, System.Type tp)
            String csname2 = "isTagFunction";
            Type cstype2 = tp;

            if (!csx.IsStartupScriptRegistered(cstype2, csname2))
                StringBuilder cstext2 = new StringBuilder();
                if (!string.IsNullOrEmpty(keywords))
                    cstext2.AppendFormat("$('head').append( '');", keywords);
                if (!string.IsNullOrEmpty(description))
                    cstext2.AppendFormat("$('head').append( '' );", description);
                if (!string.IsNullOrEmpty(title))
                  cstext2.AppendFormat("document.title = \"{0}\"; ", title);
                csx.RegisterStartupScript(cstype2, csname2, cstext2.ToString());


New ASP.Net Core 1.0

In 2002… was born ASP.NET … after 15 years we are presenting a new framework ASP.NET 5 and replace ASP.NET 4.6…

ASP.NET 5 is now ASP.NET Core 1.0.

.NET 5 is now .NET Core 1.0.

Entity Framework 7 is now Entity Framework Core 1.0 or EF Core 1.0

.NET Core introduce a new concept multi-platform and open source as you can see on the following image:

net core

for more info about .net core check the following links:


Build and Send email method to SharePoint – Using Outgoing SMTP Configuration on Central Administration.

To create and Send emails on sharepoint programmatically you can use the following code, but first you need configure the following things:

  • Configure SMTP on server.
  • Configure Outgoing E-Mail on Central Admininstration

(Central Administration > System Settings > Configure outgoing e-mail settings)

  • Oubound SMTP server is server’s IP.


StringBuilder body = new StringBuilder();
body.Append("TEXT OF BODY EMAIL"); // TextBox
string subjectEmail = "SUBJECT OF EMAIL"; // TextBox
string senderTo = ""; //TextBox

SendEmail(senderTo, subjectEmail, body);


 public bool SendEmail(string sTo, string sSubject, StringBuilder sBody)
  // Email header
  StringBuilder sHeader = new StringBuilder();

  // Email footer
  StringBuilder sFooter = new StringBuilder();

  string htmlBody = sHeader.ToString() + sBody.ToString() + sFooter.ToString();

   //Get the Sharepoint SMTP information from the SPAdministrationWebApplication
  string smtpServer = 
  string smtpFrom = 

 // Add the alternate views instead of using MailMessage.Body
  MailMessage m = new MailMessage();
  m.From = new MailAddress(smtpFrom);
  m.To.Add(new MailAddress(sTo));
  m.Subject = sSubject.ToString();
  m.Body = htmlBody;
  m.IsBodyHtml = true;

 SmtpClient client = new SmtpClient(smtpServer);

   return true;
  catch (Exception) { }
  return false;

Check if Current User is member of SharePoint Group’s – Programmatically c#

In SharePoint, we have the 3 predetermined permission groups:

  • Visitors
  • Members
  • Owners

You can see this permissions grpups in the /_layouts/permsetup.aspx page.

(Site settings->People and Groups->Settings->Setup groups)

There are properties on the SPWeb class:

  • SPWeb.AssociatedVisitorGroup
  • SPWeb.AssociatedMemberGroup
  • SPWeb.AssociatedOwnerGroup

Programmatically you can check if current user are in one of those Groups, using the following code:

bool isVisitor = false;
bool isMember = false;
bool isOwner = false;

SPWeb web = SPControl.GetContextWeb(System.Web.HttpContext.Current);
SPContext currentContext = SPContext.Current;
if (currentContext != null && currentContext.Web.CurrentUser != null)
   SPGroupCollection webGroups = web.CurrentUser.Groups;
   if (webGroups != null && webGroups.Count > 0)
       foreach (SPGroup group in web.Groups)
         if (group.ToString() == web.AssociatedVisitorGroup.ToString())
            isVisitor = web.IsCurrentUserMemberOfGroup(group.ID);
         if (group.ToString() == web.AssociatedMemberGroup.ToString())
            isMember = web.IsCurrentUserMemberOfGroup(group.ID);
          if (group.ToString() == web.AssociatedOwnerGroup.ToString())
            isOwner = web.IsCurrentUserMemberOfGroup(group.ID);
if(isVisitor == true)
 // User is Visitor
if(isMember == true)
  // User is Member
if(isOwner == true)
  // User is Owner

Hide Ribbon and SuitBar of SharePoint 2013 for a specifique Zone – Using JavaScript and C#

One way to hide Ribbon and SuitBar of SharePoint 2013 for a specific zone, like Internet for example – you can use Javascript + Css and run it in a UserControl.

1 – Create a simple UserControl on your solution and add it on your MasterPage.

In ASCX file of your UserControl add the following code:

<script type="text/javascript">
    function hideRibbon(){
        document.getElementById("s4-ribbonrow").style.display = "none !important";
        document.getElementById("suiteBar").style.display = "none !important";

On code behind of UserControl,  you go execute the javascript function, using the following code:

Example to hide in Internet zone

using Microsoft.SharePoint.Administration;

protected void Page_Load(object sender, EventArgs e)
 if (SPContext.Current.Site.Zone == SPUrlZone.Internet)

Custom menu in SharePoint using Taxonomy Term Store Navigation – Programmatically C#

This is a simple example how to access to Taxonomy Term Store properties in SharePoint using c# and create a Custom Menu.

First, create the terms on your Taxonomy Manage Navigation. – Site settings> Site Administration > Term Store Management

To get the Simple Link URL information using C#:

DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] { new DataColumn("Title"), 
                                       new DataColumn("Url") });
         foreach (var term in termSet.Terms)
            if (term.IsDeprecated == false)
                 var name = term.Name;
                 var url = term.LocalCustomProperties["_Sys_Nav_SimpleLinkUrl"];
                 dt.Rows.Add(new String[] { name, url });                 
               catch (KeyNotFoundException) { }
         rptFooter.DataSource = dt; 

Create ASPX repeater to construct your Menu

<asp:Repeater ID="rptFooter" runat="server">
  <asp:Button runat="Server" Text='<%# DataBinder.Eval (Container.DataItem, "Title") %>'
  PostBackUrl='<%# DataBinder.Eval (Container.DataItem, "Url") %>' />

The full list of Term Set properties on Manage Navigation in SharePoint 2013:

_Sys_Nav_Title: the Navigation Node Title

_Sys_Nav_FriendlyUrlSegment: the Friendly Url, also represented by the FriendlyUrlSegment property of the NavigationTerm class.

_Sys_Nav_TargetUrl: the target URL, also represented by the TargetUrl property of the NavigationTerm class.

_Sys_Nav_TargetUrlForChildTerms: the target URL for child terms, also represented by the TargetUrlForChildTerms property of the NavigationTerm class.

_Sys_Nav_CatalogTargetUrl: the catalog target URL, also represented by the CatalogTargetUrl property of the NavigationTerm class.

_Sys_Nav_CatalogTargetUrlForChildTerms: the catalog target URL for child terms, also represented by the CatalogTargetUrlForChildTerms property of the NavigationTerm class.