Skip to main content

Posts

How to check whether list item contains attachment or not using code.

To check whether the list item contains the attachment programmatically or using CSOM. Get the list item collection and then check for the attachment column.


List listEvent  = web.Lists.GetByTitle(listName);
clientContext.Load(listEvent, L => L.Id);
CamlQuery camlQuery2 = new CamlQuery();
camlQuery2.ViewXml = "<View><Query></View></Query>";
ListItemCollection item_Coll = listEventSource.GetItems(camlQuery2);
clientContext.Load(item_Coll);
clientContext.ExecuteQuery();
foreach (ListItem oLstItem in item_Coll)
  {
  bool attachmentPresent = Convert.ToBoolean(oLstItem["Attachments"]);
  if (attachmentPresent)
    {
            Console.WriteLine("Item is present");
    } 
  }


Happy Coding !!!!!
Recent posts

How to hide the left navigation in team sites

In the modern team site in SharePoint navigation section is come by default, If you want to hide the left navigation in the modern team site.


To hide the section, follow the steps.
1.  Navigate to the team site, and click on the gear icon.
2. After clicking on the gear icon, click on the site information.

3.  On clicking the site information, "edit site information" box appears. Scroll down and click on the View all site settings.


4.  On clicking the view all site settings, site settings appear, click on the Navigation Elements.
5.  On clicking Navigation Elements, uncheck the options.

6. Uncheck the options and click on OK.
7.  Now the Left navigation is disappeared from your site.


Enjoy... SharePoint.

Retrieve List Items using JSOM.

To return or get items from the list you have two options if you want to retrieve the single item you can use the GetItemById() method or for multiple items use GetItems(CamlQuery). Replace the siteUrl with your siteUrl for example ("xyz.sharepoint.com") and TitleOfList with your title list from which you want to get the items.
Code to get the list item using the ID. 
function getListiem(){ var context = new SP.ClientContext(siteUrl);  var list = context.get_web().get_lists().getByTitle('TitleOfList');  var targetListItem = list.getItemById(listItemID); context.load(targetListItem); context.executeQueryAsync(onGettingRecord, onFailedCallback); } function onGettingRecord(){ alert(targetListItem.get_item('Title')); } function onFailedCallback(sender,args){ alert('Request failed. ' + args.get_message() + '\n'+args.get_stackTrace()); }
Code to get multiple items from the list.
function getItems(){ var context = new SP.ClientContext(siteUrl); var li…

Content editor web part missing in SharePoint/Modern SharePoint.

Media and content editor web part missing in SharePoint online. At Some Point, you need to add content editor web part into modern site but the content editor web part did not appear on the page, to appear content editor web part on the page you need to follow below steps.
1 Log in as the SharePoint Global Administrator or SharePoint Administrator.
2.  Log in and navigate to your site collection ("https://xyz.sharepoint.com") and under the site settings activate below features. Site settings – site features – SharePoint Server Publishing. Site Settings – Site Actions – Manage site features- SharePoint Server Publishing Infrastructure.             For this, you also need to enable Custom site scripts on your site collection(But In Modern SharePoint Its not recommended to enabling custom site scripting) For this go to the  SharePoint Admin center – Settings -  Classic settings page (option mentioned on a page)- Scroll the page you found option for the Custom Script.  





It will …

Update SharePoint list item using JSOM.

In this blog, we are going to learn how to update the SharePoint list item using the JSOM.
To update the SharePoint list item or delete it, we can do this using the help of item id.

Here we are performing an operation on the list named "Info", which have two columns "Name" and "Address".  Replace "***.sharepoint.com" with your tenant URL and replace the ListItemID with your item id.

var clientContext = new SP.ClientContext('***.sharepoint.com');
var oList = clientContext.get_web().get_lists().getByTitle('Info');
oListItem = oList.getItemById(listItemID);
oListItem.set_item('Name','xyz'); 
oListItem.set_item('Address','xyz'); 
oListItem.update();
clientContext.executeQueryAsync(Function.createDelegate(this, this.ItemUpdate), Function.createDelegate(this, this.onQueryFailed));

function ItemUpdate(){
alert('Item updated');
}

function onQueryFailed(sender,args){
alert('Request failed. '…

Delete Item from the SharePoint list using JSOM.

In this blog, we are going to learn, how to delete SharePoint List item using JSOM/JavaScript.

We are going to delete the list item from the SharePoint list using the ID.


var clientContext = new SP.ClientContext("URL of your sharepoint tenant"); var oList = clientContext.get_web().get_lists().getByTitle('Title list '); oListItem = oList.getItemById(1)); oListItem.deleteObject(); clientContext.executeQueryAsync(Function.createDelegate(this, this.onQueryDelete), Function.createDelegate(this, this.onQueryFailed))



after successful execution of the function, it calls the onQueryDelete function and when it get failed it throws an exception.


Happy Coding!!!!!

Add list item in SharePoint List using Jsom.

In this blog, we are going to learn how to add list item into SharePoint List using Jsom/JavaScript.

Step 1:  Create a list named "Info" with two-column named Name and Address.

Step 2: Get the value of your HTML control and use this code to add an item.On Place of the "XYZ" pass value of your control.


var ctx = new SP.ClientContext("URL of your site");  
var oList = ctx.get_web().get_lists().getByTitle('Info');  
var createiteminfo = new SP.ListItemCreationInformation();  
this.ListItem = oList.addItem(createiteminfo);  
ListItem.set_item('Name',"xyz");  
ListItem.set_item('Address',"xyz");  
ListItem.update();  
ctx.load(ListItem);  
ctx.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));


On the success of this function, it calls onQuerySucceeded() function and when it throws some exception onQueryFailed() function will be called.

function onQueryS…