Search This Blog

Sunday, July 30, 2017

Get LDAP User Information Using C# with LDAP Connection

string txtEmp;
            string sa = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
            txtEmp = sa.Split('\\')[1];
            string strDLdap = ConfigurationManager.AppSettings["myLDAPString"].ToString();
            DirectoryEntry connection = new DirectoryEntry(strDLdap);
            string strDLdAPUser = ConfigurationManager.AppSettings["myLDAPUser"].ToString();
            string strDLdAPPass =ConfigurationManager.AppSettings["myLDAPPassword"].ToString();
            connection.AuthenticationType = AuthenticationTypes.Secure;
            connection.Username = strDLdAPUser;
            connection.Password = strDLdAPPass;
            DirectorySearcher dssearch = new DirectorySearcher(connection);
            dssearch.Filter = "(sAMAccountName=" + txtEmp + ")";
            SearchResult sresult = dssearch.FindOne();
            DirectoryEntry dsresult = sresult.GetDirectoryEntry();
            string strfirstName = dsresult.Properties["givenName"][0].ToString();
            string strlastName = dsresult.Properties["sn"][0].ToString();
            string Name = strfirstName + "" + strlastName;
            string strRequestedBy = dsresult.Properties["mail"][0].ToString();
            string strComapnay = dsresult.Properties["company"][0].ToString();
            displayName = dsresult.Properties["displayName"][0].ToString();
            InsertUserInfo(displayName, strComapnay, DateTime.Now.ToString("MM-dd-yyyy"), strRequestedBy);
 

Get Attachment Of List in Single Column Using Rest API



asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">
                <meta name="GENERATOR" content="Microsoft SharePoint" />
                <meta name="ProgId" content="SharePoint.WebPartPage.Document" />
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                <meta name="CollaborationServer" content="SharePoint Team Web Site" />
                <SharePoint:ScriptBlock runat="server">
                var navBarHelpOverrideKey = &quot;WSSEndUser&quot;;
                </SharePoint:ScriptBlock>
<SharePoint:StyleBlock runat="server">
body #s4-leftpanel {
                display:none;
}
.s4-ca {
                margin-left:0px;
}
</SharePoint:StyleBlock>
<style type="text/css">
#sideNavBox,#s4-titlerow,#s4-ribbonrow,#suiteBar
{
                display:none !important;
}
#contentBox
{
                margin-left:20px;
}
/*#example > thead >tr> th {
    background-color: #FFCCCC;
    color: black;
}
#example tr th {
    font-weight: bold;
    font-size: 13px;
    text-align:justify;
}
#example tr td {

                text-align:justify;
}

table tr.odd td{ background-color: white!important; }
table tr.even td{ background-color: lightgray !important; }*/
#divPostsLoader
{
                text-align:center;
                font-weight:bold;
                font-style:italic;
}
.SummeryHeader
{
                text-align:center;
                font-weight:bold;
                font-size: 17px;
    padding-bottom: 10px;
}
#example_filter
{
                margin-bottom:7px;
}
.morectnt span {
display: none;
}
/*.comment {
                width: 400px;
                background-color: #f0f0f0;
                margin: 10px;
}*/
<style type="text/css">
table#example{
                font-family: verdana,arial,sans-serif;
                font-size:11px;
                color:#333333;
                border-width: 1px;
                border-color: #666666;
                border-collapse: collapse !important;
}
table#example th {
                border-width: 1px;
                padding: 8px;
                border-style: solid;
                border-color: #666666;
                background-color: #dedede;
}
table#example td {
                border-width: 1px;
                padding: 8px;
                border-style: solid;
                border-color: #666666;
                background-color: #ffffff;
}
table.dataTable.no-footer
{
                border-collapse:collapse !important;
}

</style>
</asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderSearchArea" runat="server">
                <SharePoint:DelegateControl runat="server"
                                ControlId="SmallSearchInputBox"/>
</asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderPageDescription" runat="server">
                <SharePoint:ProjectProperty Property="Description" runat="server"/>
               
</asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">

<script type="text/javascript" src="../SiteAssets/script/jquery.min.js"></script>
<link href="../SiteAssets/bootstrap/jquery.dataTables.min.css" rel="stylesheet" type="text/css"/>
 <script src="../SiteAssets/bootstrap/jquery.dataTables.min.js" type="text/javascript"></script>

                <script type="text/javascript">
                var monthNames = [
    "Jan", "Feb", "Mar",
    "Apr", "May", "Jun", "Jul",
    "Aug", "Sep", "Oct",
    "Nov", "Dec"
];

                var urlForAllItems = "/_api/web/lists/getbytitle('NGO_App_List')/items?$Select=Category,Modified,BusinessSegment,AppOwners/Title,QueueName,Technology,ProcessArea,Domain,AppShortName,AppFullName,AppDescription,Attachments,AttachmentFiles,Editor/Title&$expand=AttachmentFiles,Editor,AppOwners";
                getItems(urlForAllItems);
                                function getItems(url) {
                                                $('#divPostsLoader').html('loading.....');
    $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + url,
        type: "GET",
        headers: {
            "accept": "application/json;odata=verbose",
        },
        success: function (data) {
                    var vtble="";
                    var srNO=1;
                    vtble +="<table id=\"example\" class=\"table table-striped table-bordered\" cellspacing=\"0\" width=\"100%\">";
                    vtble +='<thead>';
                    vtble +="<tr>";
                   // vtble +="<th style=\"width:20px !important;\">Sr.No.</th>";
                    vtble +="<th>Category</th>";
                                vtble +="<th>App Short Name</th>";
                                vtble +="<th>App Full Name</th>";
                                vtble +="<th>App Description</th>";
                                vtble +="<th>Domain / Industry</th>";
                                vtble +="<th>Process Area</th>";
                                vtble +="<th>Technology</th>";
                                vtble +="<th>Overview – Document attach</th>";
                                vtble +="<th>Queue Name</th>";
                                vtble +="<th>App Owners</th>";
                                vtble +="<th>Business Segment</th>";
                                vtble +="<th>Last updated date</th>";
                                vtble +="<th>Last updated by</th>";
            vtble +="</tr>";
                vtble +='</thead>';
                                                                                                vtble +='<tbody>';
                $.each(data.d.results, function(index, item){
               
                vtble +="<tr>";
              //  vtble +="<td>"+srNO+".</td>";
                vtble +="<td>"+item.Category+"</td>";
                vtble +="<td>"+item.AppShortName+"</td>";
                vtble +="<td>"+item.AppFullName+"</td>";
                vtble +="<td><div class=\"show\">"+item.AppDescription+"</div></td>";
                vtble +="<td>"+item.Domain+"</td>";
                vtble +="<td>"+item.ProcessArea+"</td>";
                vtble +="<td>";
                $.each(item.Technology.results, function(index, Techresults){
               
                                vtble +="<div>"+Techresults+"</div>";
               
                });
                vtble +="</td>";
                var isAttachment="false";
                vtble +="<td>";
                $.each(item.AttachmentFiles.results, function(index, Attach){
               
                                isAttachment="true";   
                                vtble +="<div><a target=\"_blank\" href=\""+Attach.ServerRelativeUrl+"\">"+Attach.FileName+"</a></div>";
               
                });
               
                if(isAttachment=="false")
                {
                                vtble +="No Attachment";
                }
                vtble +="</td>";
               
                
                vtble +="<td>"+item.QueueName+"</td>";
                vtble +="<td>"+item.AppOwners.Title+"</td>";
                vtble +="<td>"+item.BusinessSegment+"</td>";
                vtble +="<td>"+item.Editor.Title+"</td>";
                var dateCreated = new Date(item.Modified);
                vtble +="<td>"+ dateCreated.getDate() + "-" + monthNames[dateCreated.getMonth()] + "-" + dateCreated.getFullYear() +"</td>";
                vtble +="</tr>";
                srNO=srNO +1;
            });
            vtble +='</tbody>';
            vtble +="</table>";
            $('#NGOapp').html(vtble);
            table= $('#example').DataTable( {     
         "paging": true,
         "info": false,        
         "lengthChange":false,
         "pageLength": 10 
                });
                showmoreless();
                $('#divPostsLoader').empty();
            console.log(data.d.results);
        },
        error: function (error) {
            alert(JSON.stringify(error));
        }
    });
}
               
               
                function fnExcelReport()
    {
             var tab_text="<table border='2px'><tr bgcolor='#FFCCCC'>";
             var textRange; var j=0;
                 tab = document.getElementById('example'); // id of table


          for(j = 0 ; j < tab.rows.length ; j++)
          {    
                tab_text=tab_text+tab.rows[j].innerHTML+"</tr>";
                //tab_text=tab_text+"</tr>";
          }

          tab_text=tab_text+"</table>";
          tab_text= tab_text.replace(/<A[^>]*>|<\/A>/g, "");//remove if u want links in your table
          tab_text= tab_text.replace(/<img[^>]*>/gi,""); // remove if u want images in your table
                      tab_text= tab_text.replace(/<input[^>]*>|<\/input>/gi, ""); // reomves input params

               var ua = window.navigator.userAgent;
              var msie = ua.indexOf("MSIE ");

                 if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./))      // If Internet Explorer
                    {
                           txtArea1.document.open("txt/html","replace");
                           txtArea1.document.write(tab_text);
                           txtArea1.document.close();
                           txtArea1.focus();
                            sa=txtArea1.document.execCommand("SaveAs",true,"NGOappsummery.xls");
                          } 
                  else                 //other browser not tested on IE 11
                      sa = window.open('data:application/vnd.ms-excel,' + encodeURIComponent(tab_text)); 


                      return (sa);
            }
       


function showmoreless()
{
                var showTotalChar = 50, showChar = "more", hideChar = "less";
$('.show').each(function() {
var content = $(this).text();
if (content.length > showTotalChar) {
var con = content.substr(0, showTotalChar);
var hcon = content.substr(showTotalChar, content.length - showTotalChar);
var txt= con +  '<span class="dots">...</span><span class="morectnt"><span>' + hcon + '</span>&nbsp;&nbsp;<a href="" class="showmoretxt">' + showChar + '</a></span>';
$(this).html(txt);
}
});
$(".showmoretxt").click(function() {
if ($(this).hasClass("sample")) {
$(this).removeClass("sample");
$(this).text(showChar);
} else {
$(this).addClass("sample");
$(this).text(hideChar);
}
$(this).parent().prev().toggle();
$(this).prev().toggle();
return false;
});
}

                </script>
                <div id="divPostsLoader" ></div>
                <div class="SummeryHeader" id="ApplicationHeader">NGO Application Summery</div>
               
                <div style=" border-bottom:1px solid gray;"></div>
                <div style="margin-bottom:10px;">
                                <a style="float:right; color:red;font-weight:bold; text-decoration:none;margin-bottom:7px;margin-top:7px; font-style:italic;" href="javascript:void(0);" onclick="fnExcelReport()">
                                Export To Excel</a>
                </div>
                <div id="NGOapp"></div>
                <iframe id="txtArea1" style="display:none"></iframe>

                <div class="ms-hide">
                <WebPartPages:WebPartZone runat="server" title="loc:TitleBar" id="TitleBar" AllowLayoutChange="false" AllowPersonalization="false" Style="display:none;"><ZoneTemplate>
                <WebPartPages:TitleBarWebPart runat="server" HeaderTitle="Untitled_1" Title="Web Part Page Title Bar" FrameType="None" SuppressWebPartChrome="False" Description="" IsIncluded="True" ZoneID="TitleBar" PartOrder="2" FrameState="Normal" AllowRemove="False" AllowZoneChange="True" AllowMinimize="False" AllowConnect="True" AllowEdit="True" AllowHide="True" IsVisible="True" DetailLink="" HelpLink="" HelpMode="Modeless" Dir="Default" PartImageSmall="" MissingAssembly="Cannot import this Web Part." PartImageLarge="" IsIncludedFilter="" ExportControlledProperties="True" ConnectionID="00000000-0000-0000-0000-000000000000" ID="g_000aee6f_98fc_4163_906d_bfead211f9e8" AllowClose="False" ChromeType="None" ExportMode="All" __MarkupType="vsattributemarkup" __WebPartId="{000AEE6F-98FC-4163-906D-BFEAD211F9E8}" WebPart="true" Height="" Width=""></WebPartPages:TitleBarWebPart>

                </ZoneTemplate></WebPartPages:WebPartZone>
  </div>
  <table class="ms-core-tableNoSpace ms-webpartPage-root" width="100%">
                                                                <tr>
                                                                                <td id="_invisibleIfEmpty" name="_invisibleIfEmpty" valign="top" width="100%">
                                                                                <WebPartPages:WebPartZone runat="server" Title="loc:FullPage" ID="FullPage" FrameType="TitleBarOnly"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> </td>
                                                                </tr>
                                                                <SharePoint:ScriptBlock runat="server">
                                                                if(typeof(MSOLayout_MakeInvisibleIfEmpty) == &quot;function&quot;)
                                                               
                                                               
                                                               
                                                               
                                                               
                                                                {MSOLayout_MakeInvisibleIfEmpty();}</SharePoint:ScriptBlock>
                                </table>
</asp:Content>