none
How to post to someones feed? RRS feed

  • Question

  • Hi, i need to post to someones newsfeed an info. For example in this case when something changes in a purchasing system, i want to write to the responsibles newsfeed, for example that a purchasing needs to be processed. But i dont know where to start?

    Has someone a link to an example with Server Side Object Model?

    Friday, July 29, 2016 7:28 PM

Answers

  • Hi Bog,

    We can also create an Event Receiver that sends an email when an item is updated to a list.

    public override void ItemUpdated(SPItemEventProperties properties)
    {
    
    	base.ItemUpdated(properties);
    	string subject = string.Empty;
    	string from = string.Empty;
    	string to = string.Empty;
    	string bodyText = string.Empty;
    	string cc = string.Empty;
    
    	if (properties.ListTitle != "Feedback")
    	{ return; }
    	else
    	{
    
    		using (SPWeb currentWeb = new SPSite(properties.WebUrl).OpenWeb())
    		{
    			SPList list = currentWeb.Lists.TryGetList("Feedback
    			if (list == null)
    				return;
    				
    			SPListItem thisItem = properties.ListItem;
    
    			//Set email subject
    			subject = "Your Ticket Number is:  " + thisItem["TicketNumber"];
    			
    		    // Set from address
    			from = "yourmailid@robi.com.bd";
    
    			//get user or group
    			SPFieldUserValue userOrGroup = new SPFieldUserValue(currentWeb, thisItem["ConcernPerson"].ToString());
    			
    			//Check is it user or group. 
    			if (userOrGroup.User == null)
    			{
    				//If group add users email Id
    				SPGroup oGroup = currentWeb.Site.RootWeb.SiteGroups["CEx Concern Group"];
    				foreach (SPUser user in oGroup.Users)
    				{
    					to += user.Email + ",";
    				}
    			}
    			else
    			{
    				//if user then add user email id 
    				to = userOrGroup.User.Email;
    			}
    
    			//Set mail body
    			string header = "Dear Sir," + "<br />" + "<br />";
    			string body = " You body text. " + "<br />" + " " + "<br />";
    			string footer = "Thanks & regards," + "<br />" + "\n Listen2Customer";
    			bodyText = header + body + footer;              
    			StringDictionary headers = new StringDictionary();
    
    			headers.Add("fromom);
    			headers.Add("to);
    			headers.Add("cc);
    			headers.Add("bcc);
    			headers.Add("subjectbject);
    			
    			SPUtility.SendEmail(currentWeb, headers, bodyText);
    		}
    	}
    }

    Best Regards,

    Dennis


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Tuesday, August 2, 2016 9:07 AM
    Moderator

All replies

  • Hi,

    We can use a SharePoint list to store the purchasing needs data, then we can create a workflow to send an email to someone. You can set the workflow auto start when an item is changed.

    SharePoint Designer tutorial: The Send an Email action(also work in SharePoint 2013)

    https://www.youtube.com/watch?v=nNxD82KiUhQ

    Sending Emails in SharePoint 2010 and 2013 Workflows

    https://www.linkedin.com/pulse/sending-emails-sharepoint-2013-workflows-jon-raymond

    Best Regards,

    Dennis


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Monday, August 1, 2016 7:36 AM
    Moderator
  • Hi Dennis,

    thanks for your reply. Is it possible to post to a single users newsfeed through Server Side Object Model?

    best regards

    Bog

    Tuesday, August 2, 2016 8:31 AM
  • Hi Bog,

    We can also create an Event Receiver that sends an email when an item is updated to a list.

    public override void ItemUpdated(SPItemEventProperties properties)
    {
    
    	base.ItemUpdated(properties);
    	string subject = string.Empty;
    	string from = string.Empty;
    	string to = string.Empty;
    	string bodyText = string.Empty;
    	string cc = string.Empty;
    
    	if (properties.ListTitle != "Feedback")
    	{ return; }
    	else
    	{
    
    		using (SPWeb currentWeb = new SPSite(properties.WebUrl).OpenWeb())
    		{
    			SPList list = currentWeb.Lists.TryGetList("Feedback
    			if (list == null)
    				return;
    				
    			SPListItem thisItem = properties.ListItem;
    
    			//Set email subject
    			subject = "Your Ticket Number is:  " + thisItem["TicketNumber"];
    			
    		    // Set from address
    			from = "yourmailid@robi.com.bd";
    
    			//get user or group
    			SPFieldUserValue userOrGroup = new SPFieldUserValue(currentWeb, thisItem["ConcernPerson"].ToString());
    			
    			//Check is it user or group. 
    			if (userOrGroup.User == null)
    			{
    				//If group add users email Id
    				SPGroup oGroup = currentWeb.Site.RootWeb.SiteGroups["CEx Concern Group"];
    				foreach (SPUser user in oGroup.Users)
    				{
    					to += user.Email + ",";
    				}
    			}
    			else
    			{
    				//if user then add user email id 
    				to = userOrGroup.User.Email;
    			}
    
    			//Set mail body
    			string header = "Dear Sir," + "<br />" + "<br />";
    			string body = " You body text. " + "<br />" + " " + "<br />";
    			string footer = "Thanks & regards," + "<br />" + "\n Listen2Customer";
    			bodyText = header + body + footer;              
    			StringDictionary headers = new StringDictionary();
    
    			headers.Add("fromom);
    			headers.Add("to);
    			headers.Add("cc);
    			headers.Add("bcc);
    			headers.Add("subjectbject);
    			
    			SPUtility.SendEmail(currentWeb, headers, bodyText);
    		}
    	}
    }

    Best Regards,

    Dennis


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Tuesday, August 2, 2016 9:07 AM
    Moderator