Set Event Owner in Code Behind

Posted by Community Admin on 04-Aug-2018 16:51

Set Event Owner in Code Behind

All Replies

Posted by Community Admin on 17-May-2012 00:00


I am writing a custom control that will allow users to create events dynamically.  My problem comes when I try to set the event's owner.  When I do this the event doesn't save, and I don't seem to get any errors on the page or in the code, it just doesn't show up in the database.  But if I remove the code that sets the owner property, it saves correctly.  I have debugged through it and can see that the Guid that it is setting is correctly being found as the Id of my user row.  This is a snippet of the code I am using:

EventsManager manager = EventsManager.GetManager();
Event eventItem = manager.CreateEvent();
eventItem.Title = eventData["title"];
eventItem.UrlName = Regex.Replace(eventData["title"].ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
eventItem.City = eventData["city"];
eventItem.Country = eventData["country"];
eventItem.EventStart = DateTime.Parse(eventData["start"]);
eventItem.EventEnd = DateTime.Parse(eventData["end"]);
eventItem.Content = eventData["description"];
UserManager userManager = UserManager.GetManager();
eventItem.Owner = userManager.GetUser(HttpContext.Current.User.Identity.Name).Id;
Dictionary<String, String> bag = new Dictionary<String, String>();
bag.Add("ContentType", typeof(Event).FullName);
WorkflowManager.MessageWorkflow(eventItem.Id, typeof(Event), null, "Publish", false, bag);

Posted by Community Admin on 17-May-2012 00:00

hi Richard, try this line instead of the userManager.GetUser method:

eventItem.Owner = SecurityManager.GetCurrentUserId();

Hopefully that should do it. hope this is helpful!

Posted by Community Admin on 25-May-2012 00:00

Thanks, I actually ended up getting the UserManager to work

This thread is closed