Pages

Friday, May 17, 2013

Check User available in that Sharepoint Group or Not using SP Object Model


If the User available in that SP Group or Not via SP Object Model



private void GetSecurityGroup()

{

// Write your code here.

string SecurityGroupflag = "";

using (SPSite siteCollection = SPContext.Current.Site)

//using (SPSite siteCollection = new SPSite(properties.WebUrl))

{

using (SPWeb site = siteCollection.OpenWeb())

{

string groupName = "GWPSecurity";

//Get the current logged in user

SPUser currentUser = site.CurrentUser;

//Get all the user groups in the site/web

SPGroupCollection userGroups = currentUser.Groups;

//Loops through the groups and check if the user is part of given group or not.

foreach (SPGroup group in userGroups)

{

//Checking the group

if (group.Name.Contains(groupName))

{

SecurityGroupflag = "true";

break;

}

else

{

SecurityGroupflag = "false";

}

}

}

}

XPathNavigator datasource;

datasource = this.MainDataSource.CreateNavigator();

datasource.SelectSingleNode("/my:myFields/my:GWP_Security_Check_Group", NamespaceManager).SetValue(SecurityGroupflag);

}

Get Sharepoint Group User's Name and User Email id via SP Object Model


Get SP Group User's Name and User Email id via SP Object Model:

 

private void GetSecurity()

{

string GetSecurity = string.Empty;

string GetSecurityEmail = string.Empty;

using (SPSite site = new SPSite(SPContext.Current.Web.Url))

{

using (SPWeb web = site.OpenWeb())

{

SPGroup gp = web.Groups["GWPSecurity"];

if (gp != null)

{

foreach (SPUser usr in gp.Users)

{

//if (usr.Name != "System Account")

//{

if (GetSecurity == "")

GetSecurity += usr.Name;

//else

// GetSecurity += ", " + usr.Name;

if (GetSecurityEmail == "")

GetSecurityEmail += usr.Email;

else

GetSecurityEmail += ";" + usr.Email;

//}

}

}

}

}

XPathNavigator datasource;

datasource = this.MainDataSource.CreateNavigator();

datasource.SelectSingleNode("/my:myFields/my:NewSecurityName", NamespaceManager).SetValue(GetSecurity);

datasource.SelectSingleNode("/my:myFields/my:SecurityofficerEmail", NamespaceManager).SetValue(GetSecurityEmail);

}

 

Get Active Driectory Information using ASP.Net Code


You can get the below details from AD:

Get the AD First Name
Get the AD Last Name
Get the AD Email
Get the AD Designation
Get the AD Department

Use in the following Namespace :

using System.DirectoryServices;

protected string GetADUserInfo(string AccountName)
        {
            //try
            //{

            // pass the account name as "jtan" remove the Domain name and "\\".
            //production
            string ldapQueryFormat = @"LDAP://DC=APACS,DC=STARS";
            //VPC
            //string ldapQueryFormat = @"LDAP://DC=APACS,DC=local";

            string queryFilterFormat = @"(&(samAccountName=" + AccountName + ")
(objectCategory=person)(objectClass=user))";
            string email = "";
            //production
            using (DirectoryEntry root = new DirectoryEntry(ldapQueryFormat, "APAC\
\Adminshrp", "Newuser1"))
            //VPC
            //using (DirectoryEntry root = new DirectoryEntry(ldapQueryFormat, "APAC\
\Administrator", "p@ssw0rd"))
            {
                using (DirectorySearcher searcher = new DirectorySearcher(root))
                {
                    searcher.Filter = queryFilterFormat;
                    SearchResult result = searcher.FindOne();
                    DirectoryEntry dr = result.GetDirectoryEntry();
                    if (dr.Properties.Count > 0)
                    {
                        email = dr.Properties["mail"][0].ToString();
                    }
                }
            }
            return email;
            //}
            //catch (Exception ex)
            //{
            //    lblError.Text = ex.Message + "--" + ex.StackTrace;
            //}
        }

Tuesday, April 30, 2013

Hide left navigation panel without using Sharepoint designer


The users ask to remove left navigation in the Sharepoint Master pages.
You hust hide the left navigation using the below code with Content Editor
webpart








Since this web part is just added to the home page, it doesn’t hide the
left nav penal for other pages.

Once move the code in the CEWP then set the chrome type to be “None”.
 

Tuesday, April 2, 2013

Sharepoint Caluclation column

1.Display date format like "dd-MMM-yyyy"

=TEXT(StartDate,"dd-mmm-yyyy")

Namespaces for .Net Fucntionality

1. Going to use upload functionality the use the namespace

using System.IO;

if (!System.IO.File.Exists(fileToUpload))
                throw new FileNotFoundException("File not found.", fileToUpload);

Otherwise it throws error
----------------------------------------------------------------------------------------------------------------

ASP.Net Validation Controls

1. Validation for Non-Numeric and Decimal Values

It will restrict alphabets characters. It will allow only Numbers or
decimal values.

style="text-align:right" Width="53px" BackColor="#82CAFA"
BorderStyle="Dotted" BorderWidth="1px">

                                                   
runat="server" ErrorMessage="Only Number allowed"
ControlToValidate="Target"  ValidationExpression="^\d*[0-9](|.\d*[0-9]|,
\d*[0-9])?$" ValidationGroup="METVAL">

----------------------------------------------------------------------------------------------------------------