Tuesday, December 13, 2016

Send Notification email to the Assignee, change assignee and when status changes to Created BY

  Send Notification email to the Assignee, change  assignee and when status changes to Created By user









Add an event receiver to the issue tracker list:

  public enum IssueItemState
        {
            NewAssigned,
            StatusChanged
        }
        /// <summary>
        /// An item is being added.
        /// </summary>
        public override void ItemAdding(SPItemEventProperties properties)
        {
            base.ItemAdding(properties);
        }

        /// <summary>
        /// An item is being updated.
        /// </summary>
        public override void ItemUpdating(SPItemEventProperties properties)
        {
            base.ItemUpdating(properties);
            SPListItem item = properties.ListItem;
            SPUser newAssigneeUser = null;
            try
            {
                // Status Changed
                if (properties.ListItem["Status"].ToString().ToLower() != properties.AfterProperties["Status"].ToString().ToLower())
                {
                    SendNotification(item, null, IssueItemState.StatusChanged);
                }

                // New Assignee / Assignment Changed
                int userBeforeID = item.ParentList.ParentWeb.EnsureUser(item["AssignedTo"].ToString().Split('#')[1]).ID;
                int userAfterID = item.ParentList.ParentWeb.EnsureUser(properties.AfterProperties["AssignedTo"].ToString().Split('|')[1]).ID;
                newAssigneeUser = item.ParentList.ParentWeb.SiteUsers.GetByID(userAfterID);

                if (userBeforeID != userAfterID)
                {
                    SendNotification(item, newAssigneeUser, IssueItemState.NewAssigned);
                }
            }
            catch (Exception ex) { }
        }

        /// <summary>
        /// An item was added.
        /// </summary>
        public override void ItemAdded(SPItemEventProperties properties)
        {
            base.ItemAdded(properties);
            SendNotification(properties.ListItem, null, IssueItemState.NewAssigned);
        }

        /// <summary>
        /// An item was updated.
        /// </summary>
        public override void ItemUpdated(SPItemEventProperties properties)
        {
            base.ItemUpdated(properties);
        }

        protected void SendNotification(SPListItem item, SPUser newAssigneeUser, IssueItemState issueItemState)
        {
            SPUser user;
            string subject = string.Empty;
            string from = "donotreply@myEmail.co.in";
            string sendTo = string.Empty;
            string cc = string.Empty;
            string header = string.Empty;
            string bodyText = string.Empty;
            string body = string.Empty;
            string footer = string.Empty;
           var itemDispFormUrl = item.ParentList.ParentWeb.Site.MakeFullUrl(item.ParentList.DefaultDisplayFormUrl) + "?ID=" + item.ID;
            string link = @"<a href=" + itemDispFormUrl + ">Click here</a>";

            if (newAssigneeUser != null)
            {
                user = newAssigneeUser;
            }
            else
            {
                user = item.ParentList.ParentWeb.EnsureUser(item["AssignedTo"].ToString().Split('#')[1]);
            }
            sendTo = user.Email;
            SPWeb thisWeb = item.ParentList.ParentWeb;

            switch (issueItemState)
            {
                case IssueItemState.NewAssigned:

                    //Set email subject
                    subject = "New Task is assigned to you.";
                    header = "Hi " + user.Name + ",";
                    bodyText = "A new Task has been assigned to you.<br /><b>Issue Title:</b> " + item["Title"].ToString() + "<br /><b>Issue ID:</b> " + item.ID + "<br /><b>Status:</b> " + item["Issue Status"] + "<br />" + link + "to view."+ "<br />";
                    footer = "Thank you" + "<br />" + "\n (It is an auto generated email. Please do not reply.)";

                    break;

                case IssueItemState.StatusChanged:

                    subject = "Task Status of '" + item["Title"] + "' has been changed.";
                    header = "Hi " + user.Name + ",";
                    bodyText = "Task Status has been changed.<br /><b>Issue Title:</b> " + item["Title"].ToString() + "<br /><b>Issue ID:</b> " + item.ID + "<br /><b>Status:</b> " + item["Issue Status"] + "<br />" + link  +"to view." + "<br />";
                    footer = "Thanks you" + "<br />" + "\n (Note: It is an auto generated email. Please do not reply.)";

                    break;

                default:
                    break;
            }

            body = string.Format("{0} <br /><br /><{1}<br /><br />{2}", header, bodyText, footer);
            bool success = SPUtility.SendEmail(thisWeb, true, false, sendTo, subject, body);

        }


-----------------------------------Event end---------------------------------------------


Register event to the Issue Trackers list:  



Deploy Feature scoped to Web
Open an element.xml file under your projects event receiver.
Replace/Change ListUrl instead of TemplateID

<Receivers ListUrl="Lists/DevIssues">


Sign in as another user in SharePoint Personal menu


Sign in as another user in SharePoint Personal menu






Ø  SharePoint Empty Project,
Ø  Right click on project and add an empty element,
Ø  Replace the code with below.




<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
     Id="LoginAsAnotherUserDiferentUSer"
      Title="Sign in as another user?"
      GroupId="PersonalActions"
      Location="Microsoft.SharePoint.StandardMenu"
      Sequence="1000"     
    >
    <UrlAction Url="/_layouts/closeconnection.aspx?loginasanotheruser=true"/>
   
  </CustomAction>
 
</Elements>

===========================  END  ===========================


Link Under Site Actions Menu:


  <CustomAction Id="pageUnderSiteActionsMenu"
  Description="ECBDataRoomAdmin owner"
  Title="Page Cust"
  GroupId="SiteActions"
  Location="Microsoft.SharePoint.StandardMenu"
  Sequence="10">
    <UrlAction Url="~site/_layouts/15/myApp/Cust.aspx"/>
  </CustomAction>











Wednesday, December 7, 2016

Chechbox checked change event in Updatepanel




var prm = Sys.WebForms.PageRequestManager.getInstance();
    if (prm != null) {
        prm.add_endRequest(function (sender, e) {
            if (sender._postBackSettings.panelsToUpdate != null) {
                callx();
            }
        });
    };

    function callx() {
        $("#<%=chkSaveOnDocLib.ClientID%>").change(function () {
            if (this.checked) {                
                var dt = new Date();
                var time = dt.getHours() + dt.getMinutes() + dt.getSeconds();
               
                document.getElementById("txtFileName").value = document.getElementById("hdnCurrentUser").value + time;
            }
            else {
                document.getElementById("txtFileName").value = "";
            }
        });

    }

Make ASP Updatepanel component change visibility of item/Control outside of the update panel


Make ASP Updatepanel component change visibility of item/Control outside of the update panel


ScriptManager.GetCurrent(Page).RegisterPostBackControl(lblMsg);

Tuesday, November 22, 2016

ASP Control Text to symbol

ASP Control Text to symbol




<asp:LinkButton ID="lnkUp" CssClass="button" CommandArgument = "up" runat="server" Text="&#x25B2;" OnClick="" />



<asp:LinkButton ID="lnkDown" CssClass="button" CommandArgument = "down" runat="server" Text="&#x25BC;" OnClick="" />

Thursday, November 10, 2016

How to get ASP Treeview selected node value using Javascript

How to get ASP Treeview selected node value using Javascript



  function GetSelectedTreeNode() {
        debugger;
        var treeViewData = window["<%=trviewFolders.ClientID%>" + "_Data"];
        if (treeViewData.selectedNodeID.value != "") {
            var selectedNode = document.getElementById(treeViewData.selectedNodeID.value);
            var value = selectedNode.href.substring(selectedNode.href.indexOf(",") + 3, selectedNode.href.length - 2);
            var text = selectedNode.innerHTML;
             alert("Display name: " + text + "\r\n" + "NodeValue: " + value);
           // gloSelectedNodeVal = text;
        }
        else {
          // alert("No node selected.")
        }
        return false;

    }

Wednesday, November 2, 2016

Check if file exist in SharePoint Document library using JSON


Check if file exist in SharePoint Document library using JSON

<script type="text/javascript" src="//ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js"> </script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"> </script>
<script type="text/javascript" src="/_layouts/15/sp.js"> </script>


<script type="text/javascript">
       
        var retunValue = true;
        //var url = "http://ravimaloth:9870/Aaaaj/Test1/sample.doc";
        var listTitle = 'Aaaaj';
        var fileUrl = 'http://ravimaloth:9870/Aaaaj/Test1/sample.doc';

        var ctx = SP.ClientContext.get_current();
        var list = ctx.get_web().get_lists().getByTitle(listTitle);
        var qry = new SP.CamlQuery();
        qry.set_viewXml('<View Scope="RecursiveAll"><Query><Where><Eq><FieldRef Name="FileRef"/><Value Type="Url">' + fileUrl + '</Value></Eq></Where></Query></View>');
        var items = list.getItems(qry);
        ctx.load(items);
        ctx.executeQueryAsync(function () {
          
            var fileFound = (items.get_count() > 0);
            debugger;
            if (fileFound) {
                if (!window.confirm('File already exist, Are you sure you want to replace?'))                 {
                     retunValue = false;
                }              
            }          
        },
        function(sender, args) {
            console.log(args.get_message());
        });


</script>