Saturday, 20 February 2016

how to get user's name ,emaiid ,loginid and id from SPFieldUserValueCollection

  SPFieldUserValueCollection userFieldValueCollectionfunction =new  SPFieldUserValueCollection(web,convert.tostring(item[UserCollectionCoulmnName]));

                            foreach (SPFieldUserValue userFieldValuefunctin in userFieldValueCollectionfunction)
                            {
                                console.writeline( userFieldValuefunctin.User.Name);
                                console.writeline( userFieldValuefunctin.User.Email);
                            }

hide complete ribbon in dialog box using jquery

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<script type="text/javascript">

_spBodyOnLoadFunctionNames.push("hideItAll");

function hideItAll(){
 if(window.location.search.toLowerCase().indexOf("isdlg=1") > 0){
 $("#s4-ribbonrow").hide(); //ribbon bar
 }
}
</script>

hide cancel button in ribbon Sharepoint listItem form



<script type="text/javascript">
var elem = document.getElementById("Ribbon.DocLibListForm.Edit.Commit.Cancel-Large");
elem.style.display = "none";
setInterval(abc,3000);
function abc()
{
var x=document.getElementsByTagName("input");

for (var i=0; i < x.length; i++)
{
if (x.item(i).type=="button" && x.item(i).value=="Cancel")
{

x.item(i).style.display="none";
}
}
}

</script>

Header with Search textbox in ListView Webpart using Jquery

<script src="http://www.google.com/jsapi"></script>

<script>


google.load("jquery", "1.2.6");

google.setOnLoadCallback(function() {

$(document).ready(function()
{
jQuery.extend(jQuery.expr[':'], {
 containsIgnoreCase: "(a.textContent||a.innerText||jQuery(a).text()||'').toLowerCase().indexOf((m[3]||'').toLowerCase())>=0"
});


$("table.ms-listviewtable tr.ms-viewheadertr").each(function()
{
if($("td.ms-vh-group", this).size() > 0)
{
return;
}

var tdset = "";

var colIndex = 0;

$(this).children("th,td").each(function()
{
if($(this).hasClass("ms-vh-icon"))
{
// attachment
tdset += "<td></td>";
}
else
{
// filterable
tdset += "<td><input type='text' class='vossers-filterfield' filtercolindex='" + colIndex + "' /></td>";
}

colIndex++;
});

var tr = "<tr class='vossers-filterrow'>" + tdset + "</tr>";

$(tr).insertAfter(this);
});


$("input.vossers-filterfield")
.css("border", "1px solid #7f9db9")
.css("width", "100%")
.css("margin", "2px")
.css("padding", "2px")
.keyup(function()
{
var inputClosure = this;

if(window.VossersFilterTimeoutHandle)
{
clearTimeout(window.VossersFilterTimeoutHandle);
}

window.VossersFilterTimeoutHandle = setTimeout(function()
{
var filterValues = new Array();

$("input.vossers-filterfield", $(inputClosure).parents("tr:first")).each(function()
{
if($(this).val() != "")
{
filterValues[$(this).attr("filtercolindex")] = $(this).val();
}
});


$(inputClosure).parents("tr.vossers-filterrow").nextAll("tr").each(function()
{
var mismatch = false;

$(this).children("td").each(function(colIndex)
{
if(mismatch) return;

if(filterValues[colIndex])
{
var val = filterValues[colIndex];

// replace double quote character with 2 instances of itself
val = val.replace(/"/g, String.fromCharCode(34) + String.fromCharCode(34));

if($(this).is(":not(:containsIgnoreCase('" + val + "'))"))
{
mismatch = true;
}
}
});

if(mismatch)
{
$(this).hide();
}
else
{
$(this).show();
}
});

}, 250);
});
});

});

</script>

Find CheckOut files In SPLibrary or Folder in sharepoint programatically


        public static void GetCheckOutfile(SPDocumentLibrary docs)
        {
          //  foreach (SPCheckedOutFile spFiles in spFolder.Files)



            foreach (SPCheckedOutFile file in docs.CheckedOutFiles)
            {

                if (file.LeafName != file.Url.ToString().Split('/')[3])
                {
                 

                 
                         
                       console.writeLine( file.LeafName);
                 
                  }


            }




}

Hide link in ECB Menu

function HideFeatureActivatedECBMenuItem() {
    if (!CanExecuteHideForECBMenuItem()) return;

    /* find the ECB menu items which are added via feature activation */
    var ecbId = "ECBItems";
    var listName;
    if ((null != ctx.listName) && (0 < ctx.listName.length)) {
        listName = ctx.listName.toLowerCase();
        ecbId = ecbId + "_" + listName;
    }
    var elemTBody = document.getElementById(ecbId);
    if (elemTBody != null) {
        // iterate each table row to find the ECB menu item to remove (hide)
        for (var iMenuItem = 0; iMenuItem < elemTBody.childNodes.length; iMenuItem++)
 {
            var elemTr = elemTBody.childNodes[iMenuItem];
            var elemTdTitle = elemTr.childNodes[0];
            var title = GetInnerText(elemTdTitle);

            // check the ECB item title
            if (title === "Edit Item")
 {
                elemTBody.removeChild(elemTr);
 }
        }
    }
}

Create Unique Value in SSRS Dropdown Parameter

Public Shared Function RemoveDuplicates(parameter As Parameter) As String()
Dim items As Object() = parameter.Value

System.Array.Sort(items)

Dim k As Integer = 0

For i As Integer = 0 To items.Length - 1

If i > 0 AndAlso items(i).Equals(items(i - 1)) Then
Continue For

End If
items(k) = items(i)

k += 1
Next

Dim unique As [String]() = New [String](k - 1) {}

System.Array.Copy(items, 0, unique, 0, k)

Return unique
End Function






Add in Available value this code


=Code.RemoveDuplicates(parameter!dummyparameter)

change webpart header bg and color

<style>
.ms-WPHeader
{

background-color:green;

}
.ms-WPTitle A
{
  color:white !important;
}
</style>

Change the redirection behavior using jQuery on Submit button in sharepoint ListItem




<script>

$(document).ready(function() {

    var button = $("input[id$=SaveItem]");
    // change redirection behavior
        button.removeAttr("onclick");
        button.click(function() {
            var elementName = $(this).attr("name");
            var aspForm = $("form[name=aspnetForm]");
            var oldPostbackUrl = aspForm.get(0).action;
            var currentSourceValue = GetUrlKeyValue("Source", true, oldPostbackUrl);
            var newPostbackUrl = oldPostbackUrl.replace(currentSourceValue, "MyRedirectionDestination.aspx");

            if (!PreSaveItem()) return false;
            WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(elementName, "", true, "", newPostbackUrl, false, true));
        });
   
});
</script>

Add Connection String in Share point TimerJob from web.config file

 add connection string in SPTIMERJOB  




Step -1

add .dll references

Microsoft.SharePoint.Client.ServerRuntime
Path
C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.ServerRuntime.dll
System.Configuration
path
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Configuration.dll
System.Web
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Web.dll

Step -2    

add namespace

using System.Web.Configuration;
using System.Configuration;




SPWebApplication webApplication = this.Parent as SPWebApplication;
Configuration config = WebConfigurationManager.OpenWebConfiguration("/", webApplication.Name);
string conStr = config.ConnectionStrings.ConnectionStrings["myConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(conStr);