SharePoint Client Object Model Validate Specific Column is available in Library

To Check or Validate that specific column is available in Document Library use below code.

private bool ValidateDocumentLibraryColumn(string DocumentLibrary , string ListColumnName)
{
using (ClientContext clientContext = new ClientContext(SharepointSite))
{
try
{

Microsoft.SharePoint.Client.Web web = clientContext.Web;

ListCollection lists = web.Lists;

List lst = lists.GetByTitle(DocumentLibrary);

Field fld = lst.Fields.GetByInternalNameOrTitle(ListColumnName);

clientContext.Load(fld);

clientContext.ExecuteQuery();

return true;
}
catch (Exception exception)
{
ShowErrorMessage(exception.ToString());

return false;
}
}
}

 

Sharepoint Client Object Model Check Document Library is available or not

To check Document Library availability in SharePoint from Client Object Model

private bool ValidateSPLibrary(string DocumentLibrary)
{
using (ClientContext clientContext = new ClientContext(SharepointSite))
{
try
{
List existingList;

Microsoft.SharePoint.Client.Web web = clientContext.Web;

ListCollection lists = web.Lists;

IEnumerable<List> existingLists = clientContext.LoadQuery(
lists.Include(
list => list.Title)
);
clientContext.ExecuteQuery();

existingList = existingLists.FirstOrDefault(list => list.Title.ToLower() == DocumentLibrary.ToLower());

if (existingList != null)
{
return true;
}
else
{
return false;
}
}
catch (Exception exception)
{
ShowErrorMessage(exception.ToString());

return false;
}
}
}

 

Sharepoint Client Object Model Check SharePoint Site Availability

To check SharePoint Site is available or not using client object model use below code .

#region “Validatre Sharepoint Site”
private bool ValidateSPSite(string SharepointSite)
{
using (ClientContext clientContext = new ClientContext(SharepointSite))
{
try
{
clientContext.Credentials = System.Net.CredentialCache.DefaultCredentials;

Microsoft.SharePoint.Client.Web web = clientContext.Web;

Microsoft.SharePoint.Client.Web site = clientContext.Web;

clientContext.Load(site);

clientContext.ExecuteQuery();

return true;
}
catch (Exception)
{
return false;

throw;
}
}
}
#endregion

Parameter SharepointSite is the name of Sharepoint Site which we want to check that if it is exist or not.

 

 

 

Asp.Net Call JavaScript Function From Code Behind

To call JavaScript function from code behind

protected void ShowModalPopup()
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(@”<script language=’javascript’>”);
sb.Append(@”ShowModal()”);
sb.Append(@”</script>”);

if (!ClientScript.IsStartupScriptRegistered(“JSScript”))
{
ClientScript.RegisterStartupScript(this.GetType(), “JSScript”, sb.ToString());
}
}

In above code ShowModal() is a javascript function which performs operation to open modal popup from using script.

ASP.Net File Upload file extension Validation Client Side

To Validate file extension of File before upload use below  Jquery code.

< script type = “text/javascript” >

function Validation() {

var uploadcontrol = $(“[id$=fuImageUpload]”).val();

if (uploadcontrol.length > 0) {

var validFilesTypes = [“bmp”, “gif”, “png”, “jpg”, “jpeg”, “doc”, “xls”];

var file = $(“[id$=fuImageUpload]”).val();
var path = file;
var ext = path.substring(path.lastIndexOf(“.”) + 1, path.length).toLowerCase();
var isValidFile = false;
for (var i = 0; i < validFilesTypes.length; i++) {
if (ext == validFilesTypes[i]) {
isValidFile = true;
break;
}
}

if (!isValidFile) {
alert(“Invalid File. Please upload a File with extension:\n\n” + validFilesTypes.join(“, “));
return false;
}
} else {
alert(“Please select file.”);
return false;
}

}

< / script >