Showing posts with label Server Side. Show all posts
Showing posts with label Server Side. Show all posts

Thursday, 12 February 2015

SharePoint2013: Getting user(s) from people picker control and set value to people picker column in SharePoint listitem

Getting user(s) from people picker control and set value to people picker column in SharePoint listitem:

                            SPWeb mySite = SPContext.Current.Web;
                            SPListItemCollection listItems = mySite.Lists["myList"].Items;
                            SPListItem item = listItems.Add();

                           //getting value from People picker control                            
                            string[] UsersSeperated = pplEditor.CommaSeparatedAccounts.Split(',');
                            SPFieldUserValueCollection UserCollection = new SPFieldUserValueCollection();
                            foreach (string UserSeperated in UsersSeperated)
                            {
                                mySite.EnsureUser(UserSeperated);
                                SPUser User = mySite.SiteUsers[UserSeperated];
                                SPFieldUserValue UserName = new SPFieldUserValue(mySite, User.ID, User.LoginName);
                                UserCollection.Add(UserName);
                            }
                            item["people"] = UserCollection;
                            item.Update();

SharePoint 2013: Sending Mail in SharePoint using SPUtility

Sending Mail in SharePoint using SPUtility Method:

If you want to send a mail from SharePoint from server side. use below function:

            StringDictionary headers = new StringDictionary();
            headers.Add("to", strTo);
            headers.Add("cc", strCC);
            headers.Add("bcc", strbcc);
            headers.Add("from", strFrom);
            headers.Add("subject", strSubject);
            headers.Add("content-type", "text/html");
            StringBuilder mailbody = new StringBuilder();
            mailbody.AppendLine("The following request has been assigned to you:<br/>");
            mailbody.AppendLine("<br/>");
            mailbody.AppendLine("clicking on the following link: <a href='" + Link + "'>" + Request Name + "</a><br/>");
            SPUtility.SendEmail(web, headers, mailbody);

SharePoint 2013: Show Modal Popup Window in Application Page

Show Modal Popup Window in Application Page

I want to show the modal Popup window from my application page, for that we need to call the below JS file inside your application page.

<script type="text/javascript" src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>

And the call the Jquery function for modal Popup your application page as below we called:

<script type="text/javascript">
        function showModalPopup() {
            alert('Bala testing on this');
            try {
                var options = {
                    width: 630,
                    height: 500,
                    title: "Edit SR Request",
                    bgcolor: '#000000',
                    url: "/_layouts/15/GridVewSort/Seekopinion.aspx?Reqno=USA&list=countries",
                }
            }
            catch (e) {
            }
            SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
            return false;
        }
</script>

If you want to cancel the modal Popup window without refresh your screen. you can use below script in cancel button client click:

<asp:Button ID="btnCancel" runat="server" Text="Cancel"  CssClass="btnclass" OnClientClick="javascript: window.frameElement.commitPopup();" />