Tuesday, March 11, 2014

Find out current user exists in an AD group or not

Hi, I have a requirement to find out whether the userrent user is belongs to a specific AD group or not. I struggle a lot to find out the solution. Finally I achieved with the below solution.
Step1 : Add the AD group in a sharepoint group
Step 2: Go to the Site Permission ->Groups
Step 3: AD group name will be appear in the "_layouts/15/groups.aspx" page.
Step 4: Note down the AD group name ID
Step 5:Below code required to check the ID
SPContext.Current.Web.IsCurrentUserMemberOfGroup(ID if AD group name noted on step 4)
:)

Use of Array.Foreach() Method

string fileName ="abc#!.txt"; string specialChars = @"\/:*?""<>^|#%&{}~"; Array.ForEach(specialChars.ToCharArray(), specialChar => fileName = fileName.Replace(specialChar, ' '));

Make valid file name for Sharepoint

Hello, We are some times facing problem to validate a file name for sharepoint for special characters. Below is the code for the same :) private string GetValidFileName(string currentFileName) { //this.currentFileNameTemp = currentFileName; string fileName = currentFileName; //special chars not allowed in filename string specialChars = @"\/:*?""<>^|#%&{}~"; //Replace special chars in raw filename with empty spaces to make it valid Array.ForEach(specialChars.ToCharArray(), specialChar => fileName = fileName.Replace(specialChar, ' ')); fileName = fileName.Replace(" ", string.Empty); return fileName; }