Friday 31 January 2014

Add SharePoint list choice field data to dropdown Programatically using SPField Class

Add SharePoint list choice field data to dropdown


SPSite oSite = new SPSite(url);
     SPWeb myWeb = oSite.OpenWeb();
    SPFieldChoice myField = (SPFieldChoice)myWeb.Lists["List Name"].Fields["FieldName"];
    DataTable dataTasks = new DataTable();
    DataColumn[] dtCols = new DataColumn[] { new DataColumn("FieldName", Type.GetType("System.String")) };
    dataTasks.Columns.AddRange(dtCols);
    for (int i = 0; i < myField.Choices.Count; i++)
     {
        DataRow dRow = dataTasks.NewRow();
        dataTasks.Rows.Add(Convert.ToString(myField.Choices[i]));
     }
    this.DrpTask.DataSource = dataTasks;
    this.DrpTask.DataValueField = Convert.ToString(dataTasks.Columns["FieldName"]);
     this.DrpTask.DataTextField = Convert.ToString(dataTasks.Columns["FieldName"]);
    this.DrpTask.DataBind();
     this.DrpTask.Items.Insert(0, "All");

Thursday 30 January 2014

Create a Slide Show in SharePoint 2010 using an Announcements List and SPServices

   

  • The first step was using the Announcements list for the announcements slider.  Then create two custom list columns, “Image” and “Body”. The “Image” column is a “Hyperlink or Picture” column type and “Body” is a “multiple lines of text” column type.

  • Reference SP Services, jQuery, jShowoff, and copy below JavaScript code to pull an image column from the Announcements list.


$(document).ready(function () {
 var emptyResults = "<div class='sliderDiv'><p class='announceTitle'>Company Name</p></div>";
  var maxVal = 0;
  var toShow = false;
  var heightTemp = 0;
  $().SPServices({
    operation : "GetListItems",
    async : false,
    listName : "Announcements",
    CAMLViewFields : "<ViewFields><FieldRef Name='Title' /><FieldRef Name='Image' /><FieldRef Name='Body' /><FieldRef Name='Modified' /></ViewFields>",
    CAMLQuery : "<Query><OrderBy><FieldRef Name='Created' /></OrderBy>" + "<Where><Or><Geq><FieldRef Name='Expires' /><Value Type='DateTime'>" + "<Today /></Value></Geq><IsNull><FieldRef Name='Expires' /></IsNull></Or></Where></Query>",

    completefunc : function (xData, Status) {
      var itemCount = $(xData.responseXML).SPFilterNode("rs:data").attr("ItemCount");
      if (itemCount > 0) {
        toShow = true;

        $(xData.responseXML).SPFilterNode("z:row").each(function () {
          var modDate = $(this).attr("ows_Modified");
          modDate = modDate.substr(5, 2) + "/" + modDate.substr(8, 2) + "/" + modDate.substr(0, 4);

          var titleHtml = "<div class='sliderDiv'><p class='announceTitle'>" + $(this).attr("ows_Title") + "</p>";
          var imgBody = "<img class='anImage' src='" + $(this).attr("ows_Image").split(',')[0] + "'></img>";
          var bodyHtml = "<p class='announceBody'>" + $(this).attr("ows_Body") + "</p>";
          var expireHtml = "<p class='announceFooter'>Modified: <span>" + modDate + "</span></p></div>";

          //div announcements is added by jshowoff js.

         $("#announcements").append(titleHtml + imgBody + bodyHtml + expireHtml);

        });

      } else {

        $("#announcements").append(emptyResults);

      }

    } //completefunc

  }); //SPServices

  if (toShow == true) {
    $('.sliderDiv').each(function () {
      heightTemp = $(this).height();
      if (heightTemp > maxVal) {
        maxVal = heightTemp
      };
    });
    $('#announcements').css('min-height', maxVal);
    $('#announcements').jshowoff({
      speed : 12000,
      changeSpeed : 3000,
      controls : true,
      animatePause : false,
      effect : 'fade',
      cssClass : true,
      links : true
    });
  } //if stm
}); //ready

Tuesday 28 January 2014

Hiding Share Option in Document Library Callout Actions

To Hide Share Option in Document Library Callout Actions add below script.



<script type="text/ecmascript">
(function(){
if (typeof(_spBodyOnLoadFunctions) === 'undefined' || _spBodyOnLoadFunctions === null) {
return;
}
_spBodyOnLoadFunctions.push(function() {

if (typeof(SPClientTemplates) === 'undefined' || SPClientTemplates === null || (typeof(APD_InAssetPicker) === 'function' && APD_InAssetPicker())) {
return;
}
var registerOverrideToHideSocialActions = function(id) {
var socialactionsOverridePostRenderCtx = {};
socialactionsOverridePostRenderCtx.BaseViewID = 'Callout';
socialactionsOverridePostRenderCtx.ListTemplateType = id;
socialactionsOverridePostRenderCtx.Templates = {};
socialactionsOverridePostRenderCtx.Templates.Footer = function(renderCtx) {
var  renderECB;
if (typeof(isSharedWithMeView) === 'undefined' || isSharedWithMeView === null) {
renderECB = true;
} else {
var viewCtx = getViewCtxFromCalloutCtx(renderCtx);
renderECB = !isSharedWithMeView(viewCtx);
}
// By setting a null value as 2nd parameter, we do not specify additional callout actions.
return CalloutRenderCustomFooterTemplate(renderCtx, null, renderECB);
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(socialactionsOverridePostRenderCtx);
}
// Hide actions for default Document Libraries
registerOverrideToHideSocialActions (101);
// Hide actions for the document library on your My Site
registerOverrideToHideSocialActions (700);
function CalloutRenderCustomFooterTemplate(renderCtx, calloutActionMenuPopulator, renderECB) {
if (typeof calloutActionMenuPopulator === 'undefined' || calloutActionMenuPopulator === null) {
calloutActionMenuPopulator = CalloutOnPostRenderCustomTemplate;
}
if (typeof renderECB === 'undefined' || renderECB === null) {
renderECB = true;
}
var calloutID = GetCalloutElementIDFromRenderCtx(renderCtx);
AddPostRenderCallback(renderCtx, function() {
var calloutActionMenu = new CalloutActionMenu(calloutID + '-actions');
calloutActionMenuPopulator(renderCtx, calloutActionMenu);
calloutActionMenu.render();
});
var ecbMarkup = [];
if (renderECB) {
ecbMarkup.push('<span id=' + StAttrQuote(calloutID + '-ecbMenu') + ' class="js-callout-actions js-callout-ecbActionDownArrow">');
ecbMarkup.push(RenderECBinline(renderCtx, renderCtx.CurrentItem, renderCtx.CurrentFieldSchema));
ecbMarkup.push('</span>');
}
return Callout.GenerateDefaultFooter(calloutID, ecbMarkup.join(''));
}
function CalloutOnPostRenderCustomTemplate(renderCtx, calloutActionMenu) {
var listItem = renderCtx.CurrentItem;
var openText = GetCallOutOpenText(listItem, renderCtx);
calloutActionMenu.addAction(new CalloutAction({
text: openText,
onClickCallback: function(calloutActionClickEvent, calloutAction) {
CalloutAction_Open_OnClick(calloutActionClickEvent, calloutAction, renderCtx);
}
}));
}
});
})();

</script>

Hiding the Social Actions (Follow / Share) from the Document Libraries in SharePoint 2013

First of all, hiding the follow and share actions on your site is not that difficult. They can be hidden by some custom CSS
                                    pic1

Hiding Document Library Callout Actions

Hiding the callout actions in the document library is a bit more difficult, because the links do not have a specific ID or Class defined.
                                   pic1
The trick is to override the default callout that is generated for the document libraries. This is also what SharePoint does, they are overriding the default callout to add the Follow action in the callout.
To override the default document library callouts and hide the Follow action, you can use the following code:
<script type="text/ecmascript">
(function(){
if (typeof(_spBodyOnLoadFunctions) === 'undefined' ||
_spBodyOnLoadFunctions === null) {
return;
}
_spBodyOnLoadFunctions.push(function() {

if (typeof(SPClientTemplates) === 'undefined' || SPClientTemplates
=== null || (typeof(APD_InAssetPicker) === 'function' && APD_InAssetPicker())) {
return;
}
var registerOverrideToHideSocialActions = function(id) {
var socialactionsOverridePostRenderCtx = {};
socialactionsOverridePostRenderCtx.BaseViewID = 'Callout';
socialactionsOverridePostRenderCtx.ListTemplateType = id;
socialactionsOverridePostRenderCtx.Templates = {};
socialactionsOverridePostRenderCtx.Templates.Footer =
function(renderCtx) {
var renderECB;
if (typeof(isSharedWithMeView) === 'undefined' ||
isSharedWithMeView === null) {
renderECB = true;
} else {
var viewCtx = getViewCtxFromCalloutCtx
(renderCtx);
renderECB = !isSharedWithMeView(viewCtx);
}
// By setting a null value as 2nd parameter, we do
not specify additional callout actions.
return CalloutRenderCustomFooterTemplate(renderCtx,
null, renderECB);
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides
(socialactionsOverridePostRenderCtx);
}
// Hide actions for default Document Libraries
registerOverrideToHideSocialActions (101);
// Hide actions for the document library on your My Site
registerOverrideToHideSocialActions (700);
function CalloutRenderCustomFooterTemplate(renderCtx,
calloutActionMenuPopulator, renderECB) {
if (typeof calloutActionMenuPopulator === 'undefined' ||
calloutActionMenuPopulator === null) {
calloutActionMenuPopulator =
CalloutOnPostRenderCustomTemplate;
}
if (typeof renderECB === 'undefined' || renderECB === null)
{
renderECB = true;
}
var calloutID = GetCalloutElementIDFromRenderCtx
(renderCtx);
AddPostRenderCallback(renderCtx, function() {
var calloutActionMenu = new CalloutActionMenu
(calloutID + '-actions');
calloutActionMenuPopulator(renderCtx,
calloutActionMenu);
calloutActionMenu.render();
});
var ecbMarkup = [];
if (renderECB) {
ecbMarkup.push('<span id=' + StAttrQuote(calloutID
+ '-ecbMenu') + ' class="js-callout-actions js-callout-ecbActionDownArrow">');
ecbMarkup.push(RenderECBinline(renderCtx,
renderCtx.CurrentItem, renderCtx.CurrentFieldSchema));
ecbMarkup.push('</span>');
}
return Callout.GenerateDefaultFooter(calloutID,
ecbMarkup.join(''));
}
function CalloutOnPostRenderCustomTemplate(renderCtx,
calloutActionMenu) {
var listItem = renderCtx.CurrentItem;
var openText = GetCallOutOpenText(listItem, renderCtx);
calloutActionMenu.addAction(new CalloutAction({
text: openText,
onClickCallback: function(calloutActionClickEvent,
calloutAction) {
CalloutAction_Open_OnClick
(calloutActionClickEvent, calloutAction, renderCtx);
}
}));
}
});
})();
</script>

The result looks like this:
                                              pic1

How to Enable “Sign In As Different User” option in SharePoint 2013

To Get “Sign In As Different User” Option in SharePoint 2013 Follow these steps:
Locate and then open the following file in a text editor: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\CONTROLTEMPLATES\Welcome.ascx
Add the following element before the existing “ID_RequestAccess” element:
<SharePoint:MenuItemTemplate runat=”server” ID=”ID_LoginAsDifferentUser” Text=”<%$Resources:wss,personalactions_loginasdifferentuser%>” Description=”<%$Resources:wss,personalactions_loginasdifferentuserdescription%>” MenuGroupId=”100″ Sequence=”100″ UseShortId=”true” />
Save the file.