Saturday 20 July 2013

Programmatically Checking the SharePoint List Attachments in a Synchronous Event

Hellooooo!!!!!
 Hope things are going great.
 I am working on Item Updating event receiver for a custom list : listitem , afterproperties , beforeproperties , blah , blah, blah.. And I am on the last step, and it is to find whether attachment is associated with the current item..

Simple????!!!!!    Lets see..
int attachmentcount1 = Convert.ToInt32(properties.BeforeProperties["Attachments"]);
int attachmentcoun2 = Convert.ToInt32(properties.ListItem["Attachments"]);
int attachmentcount3 = Convert.ToInt32(properties.AfterProperties["Attachments"]);
what I am getting, “0” on all the three variables..
So wat is the fix, to check for the “Attachments” in the “Synchronous” event..


public class MyEventReceiver : SPItemEventReceiver
 
{
HttpContext currentContext;

public MyEventReceiver()
{
currentContext = HttpContext.Current;
}
   
public override void ItemAdding(SPItemEventProperties properties)
 {
         
if (currentContext != null)
   {
       if (currentContext.Request.Files.Count > 0)
      {
            // Thers are attachments

      }
else
      {
        // no attachments
      }
   }                        
  }
 }


This works on the case of Item Adding also.. :D

See you again.. Cyaa...

Monday 15 July 2013

Hide "Upload Multiple Documents" tab in the Ribbon - SharePoint

Hello all,
Today i will tell you one small , but very intersting thing regarding the ribbon control..

In this post, i have told u how to hide a ribbon button for a specific library with ease.Now, The same thing but in a different requirement..

U r asked to hide "Upload Multiple Documents" tab which is a dropdown of "Upload Document" tab.




 My previous post was about hiding a entire button, not a dropdown option in it :P

No need to panic.. just copy the below lines and paste it in your Content Editor WebPart(refer this for help).


<style type="text/css">

#Ribbon\.Documents\.New\.AddDocument\.Menu\.Upload\.UploadMultiple-Menu32

{
display:none !important;
}

</style>


Now u can see, the dropdown option is gone... :D

Cooooooooool:D

Saturday 6 July 2013

GUID of a SharePoint List or Library


One fine Day,
 We were woking on something related to triggering a workflow through an event handler. We needed GUID of the List in that process. hhhmmmmmm.. How to get that?

My friend was trying something through object model or through JSOM or Poershell to get the GUID..
Any other ways???

Obviously Yes, I got one easy Detour...


Navigate to that SharePoint list in browser. Select the List Settings in Ribbon and copy the Url from the browser address into Notepad.

At the end of the URL, u will see something like:     List=%7B69238662%2D566D%2D4995%2D9927%2D5C47F16B22DB%7D

In that  

replace “%7B” with “{”
replace all “%2D” with “-“
replace “%7D” with “}”

Now you have the GUID of the list:



{69238662-566D-4995-9927-5C47F16B22DB}


Piece of cake...... Have a great day..