Get Current Login User Details in SharePoint Web

 public class CurrentEmployeDetails
public static string loginName;
public static SPSite site;
public static string userName;

public static SPWeb Web()
site = new SPSite(SPContext.Current.Web.Url);
SPWeb web = site.OpenWeb();
return web;
public static string LoginName() // Returns Current Login User’s Login Name
loginName = Web().CurrentUser.LoginName.ToString();
return loginName;

public static string UserName() //Returns Current Login User’s User Name
userName = Web().CurrentUser.Name.ToString();
return userName;

Check Folder Exits in Sharepoint Document Library

using (SPSite site = new SPSite("Site Url"))

using (SPWeb web = site.OpenWeb())
//Check Folder path (Floder Already Exits or Not)
if (web.GetFolder(“DocumentLibraryName”/”FolderName”).Exists)
//Do Something

CAML Query for get only View Fields not all List Items in SharePoint List

//Get SharePoint List from SharePoint Site
SPList listEmp = currentWeb.Lists["Employee_Master"];

//Create SharePoint Query Object for use CAML Query
SPQuery qryEmp = new SPQuery();

//CAML Query to Get SharePoint List Records SharePoint List ( SPQuery object & CAML)

qryEmp.Query = “” + Name + “”;

//Select what are the fields you want to retrieve from CAML Query.(Not all Columns from SharePoint List)

qryEmp.ViewFields = string.Concat(
“<FieldRef Name=’Employee_ID’ />”,
“<FieldRef Name=’First_Name’ />”,
“<FieldRef Name=’Email’ />”,
“<FieldRef Name=’Login_ID’ />”,
“<FieldRef Name=’Immidiate_Supervisor’ />”,
“<FieldRef Name=’Department’ />”);

qryEmp.ViewFieldsOnly = true;

//Assign result data set (which are get from CAML Query with View Fields) to SPListItem Collection

SPListItemCollection itemCollectionEmp = listEmp.GetItems(qryEmp);

Elevate Privileges on C# Code in SharePoint


// This code scope runs as a System Account – Code run with elevated Privilages

using (SPSite currentSite = new SPSite(SPContext.Current.Site.Url))
using (SPWeb currentWeb = currentSite.OpenWeb())
currentSite.AllowUnsafeUpdates = true;
currentWeb.AllowUnsafeUpdates = true;

//Things what do you want

currentWeb.AllowUnsafeUpdates = false;
currentSite.AllowUnsafeUpdates = false;


Assign Current Url Parameters to Tags

Assigning Url Parameters ( – url parameter is “Id”) to Tags.

url –

Method Used –¬†<%=Request.QueryString[“Url Parameter Name”] %>

This method can use any where in to get parameters of current url.

Example :

<a href=”http://udaradocs.aspx?Doc=<%=Request.QueryString%5B“Id”%5D %>”