Set Event Owner in Code Behind
Hi,
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;manager.SaveChanges();Dictionary<String, String> bag = new Dictionary<String, String>();bag.Add("ContentType", typeof(Event).FullName);WorkflowManager.MessageWorkflow(eventItem.Id, typeof(Event), null, "Publish", false, bag);hi Richard, try this line instead of the userManager.GetUser method:
eventItem.Owner = SecurityManager.GetCurrentUserId();Thanks, I actually ended up getting the UserManager to work