Querying Person or Group Column in SharePoint List using CAML

This is the one of best way to Querying Person or Group Column in SharePoint List,

SPList list = Web.Lists.TryGetList("ListName");

SPQuery qryEmp = new SPQuery();

qryEmp.Query = "<Where><And><Eq><FieldRef Name='ColumnName' LookupId='TRUE' /><Value Type='Integer'>" + UserId + "</Value></Eq> </Where>";


Create UpdatePanel Postback waiting message in Asp.net

Below i show you how to give waiting message during the postback of updatepanel in asp.net
I used “BackGroudWaiting” CSS class as background style.

Background style CSS
position: fixed; text-align: center; height: 100%; width: 100%; top: 0; right: 0; left: 0; z-index: 9999999; background-color: #000000; opacity:0.8;

Using .gif Image as waiting message



and also we can use customly created div as waiting msg, below is the example with CSS.


Message CSS Styles
.WaitingMessageStyle {
position: fixed;
padding: 50px;
background-color: #050404;
font-size: 36px;
left: 30%;
top: 45%;
color: #FFF;
border-style: groove;
border-width: 1px;
border-color: #5A5A55;

Hope you learned something throw this post,
Udara Eshan

Send Email with Attachment using C# & SMTP

//Create New MailMessage Object
MailMessage mailMessage = new MailMessage();

//Set SMTP From Address
mailMessage.From = new MailAddress(smtpFrom);

//Set Receiver’s Address
mailMessage.To.Add("Mail Receiver's Address ( Can use ';' separated for bulk addresses"“);

//Enable HTML Tags inside the mail Body
mailMessage.IsBodyHtml = true;

//Set the subject and body of the message
mailMessage.Subject = “Subject”;

//If your are using some multi-line textbox to body you can use mailMessage.Body=BodyTextBox.Text.Replace(Environment.NewLine, "</br>") to separate line by line

//Create WebClient object to Access Attachment
WebClient webClient = new WebClient();

//Parse net credentials, if you want to parse default network creadentials you can use like this,
webClient.Credentials = CredentialCache.DefaultNetworkCredentials;
But some times if there has some permission issues with that default network credentials this will not work,
So better option is use one service account for access web client like below

webClient.Credentials = new NetworkCredential("username","Password","Domain");

//Set document to byte array
byte[] data = webClient.DownloadData("Attachement url");

//get it into Memory stream
MemoryStream memoryStreamOfFile = new MemoryStream(data);

//Add Attachment to mail
mailMessage.Attachments.Add(new System.Net.Mail.Attachment(memoryStreamOfFile, "Document Name"));

//Create the SMTP client object and send the Email, that’s all
SmtpClient smtpClient = new SmtpClient("smtpServer");


Hope you learned throw this, Have a nice day, will meetup with new thing,
Udara Eshan

Create Popup form with Ajax and Asp.net

First you need to add Ajax assembly reference to Asp.net page,


Then Add ScriptManager and  ModalPopupExtender to asp.net form shown as below


after that create Pop form as you want, i have given an example below


finally publish the solution and click Show popup button then you can get popup window like below,


if you want to access controller events inside the popup window, use asyncPostBackTrigger to access this controller in postback.


Hope you learned something throw this post,

Thanks & Regards


Get SharePoint List Items to SPListItemCollection using CAML with Two Parameters

using (SPSite oSpSite = new SPSite(SPContext.Current.Web.Url))
using (SPWeb oSPWeb = oSpSite.OpenWeb())

int Parameter_Id = 12; //Sample Interger Variable

sting Parameter_Name =”Udara” //Sample string variable

SPList list = oSPWeb.Lists.TryGetList(“SharePoint List”);

SPQuery qryEmp = new SPQuery();

qryEmp.Query = “<Where><And><Eq><FieldRef Name=’Id’/><Value Type=’Integer’>” +Parameter_Id+ “</Value></Eq><Eq><FieldRef Name=’Name’/><Value Type=’Text’>” + Parameter_Name + “</Value></Eq></And></Where>”; // CAML Query with two parameters

SPListItemCollection oSpListCln = list.GetItems(qryEmp); // Querying List



Get Absolute url from uploaded document in SharePoint

String DocUrl = file.Item[SPBuiltInFieldId.EncodedAbsUrl].ToString();

Upload Document to SharePoint Document Library

private void UploadDocument()
using (SPSite site = new SPSite(SPContext.Current.Web.Url))
using (SPWeb web = site.OpenWeb())
SPDocumentLibrary documentLib = web.Lists.TryGetList(“Document Libarry name”) as SPDocumentLibrary;

Stream fStream = DocumentFileUpload.PostedFile.InputStream; // get Input stream from Document Library

byte[] _byteArray = new byte[fStream.Length];

fStream.Read(_byteArray, 0, (int)fStream.Length);


web.AllowUnsafeUpdates = true;

string _fileUrl = documentLib.RootFolder.Url + “/” +Path.GetFileNameWithoutExtension(DocumentFileUpload.PostedFile.FileName) + Path.GetExtension(DocumentFileUpload.PostedFile.FileName); // Set Document uploaded url

bool IsOverwriteFile = true; // Overwrite document true

SPFile file = documentLib.RootFolder.Files.Add(_fileUrl, _byteArray, IsOverwriteFile);

SPListItem item = file.Item;



web.AllowUnsafeUpdates = false;