Geeks With Blogs

News
About Me:
I am a Female SharePoint Developer (a platinum unicorn). I have been working with SharePoint since I attended the Portal University in 2005. I hold a BA in Computer Science from the University of Missouri - Kansas City. I love playing Rockband, organizing user group meetings, working with code, attending events as a speaker or organizer, and having bizarre conversations about geek things with cool people. If you have any comments or questions fill out the contact form and I will try my best to help.



The Guide of a MOSSLover Becky Isserman's Blog

At work they wanted me to create a 2 question survey that allowed the users to post as many times as they wanted anonymously on multiple sites.  I had created a document library on multiple sites using a console application, but I had never created a survey.  They also wanted there domain users to have access to the survey, so that they could post and not delete or edit the surveys plus a couple of alerts setup.  The sites already existed and were being created from a template, so I just updated the template initially.  The second part dealt with some custom code that I wrote against this custom survey template.  Here is an example of how you would create off of a custom survey template, add the permissions, then add the alerts using the SharePoint Object Model:
                string listName = "Rate This Site";
                string listDescription = "Site Rating.";
               
                try
                {
                    SPListTemplateCollection SurveyTemplateCollection =
                    site.GetCustomListTemplates(WebName);

                    SPListTemplate SurveyTemplate = SurveyTemplateCollection["Survey Template Name"];


                    //creates survey using custom template, must do an update on the web before making changes
                   //i.e. adding alerts and permissions
                    WebName.Lists.Add(listName, listDescription, SurveyTemplate);

                    WebName.Update();

                
                    SPList ListName= WebName.Lists[List Name];

                   //add a SharePoint User Group to the list and does not inherit permissions from the site
                    ListName.BreakRoleInheritance(false); //set to true if you are only adding a group
                   SPGroup RegularUser = WebName.SiteGroups["Group Name"];
                    SPRoleDefinition RoleDefinition;
                    SPRoleAssignment RoleAssignment;
                    RoleDefinition = WebName.RoleDefinitions["Permission Name"];
                    RoleAssignment = new SPRoleAssignment(RegularUser);
                    RoleAssignment.RoleDefinitionBindings.Add(RoleDefinition);
                    ListName.RoleAssignments.Add(RoleAssignment);

                    SPGroup GroupName = ChangeNAPWeb.SiteGroups[Group Name];
                    foreach (SPUser UserName in GroupName.Users)

                    {
                        
//setup alerts for a specific user
                       if (UserName.LoginName == "username with domain in caps")
                        //domain name is always in caps

                        {
                            SPAlert alert = WebName.Alerts.Add();
                            alert.AlertType = SPAlertType.List;
                            alert.Title = "Title of Survey";
                            alert.EventType = SPEventType.All;
                            alert.AlertFrequency = SPAlertFrequency.Immediate; //this is for immediate alerts
                            alert.User = UserName
                            alert.List = List;
                            alert.Status = SPAlertStatus.On;
                            alert.Update(true);
                        }
                    }

                    localList.Update(); //if you don't include this statement then the survey will not be updated
              }
               catch(Exception ex)
                {
                }

If you would like any additional information or you have a comment or question let me know.  I believe on my old blog there is an entry on how you would set this up in a Console Application and how you could add information to the quick launch bar programmatically.  If you don't like how it adds the survey to the top of the quick launch bar you can add the following code: ListName.OnQuickLaunch = false;
Then you can go back to my old post and look at the code on how to add the link to the point in the quicklaunch where you would like.  I hope that you enjoy the code.

Technorati Tags: ,
Posted on Thursday, February 21, 2008 1:22 PM MOSS | Back to top


Comments on this post: Adding a New Survey to SharePoint w/ Alerts and Custom Permissions

# re: Adding a New Survey to SharePoint w/ Alerts and Custom Permissions
Requesting Gravatar...
Hi, great write-up, i have one real question.

Now I want to programatically(through object model) pull the details of the survey and put it into a database, would you please give an example where i can just read the survey details through code..
your help would be much appreciated.

you can pass the example to my mail as well.

ghoshdipanjan@hotmail.com
Left by Dipanjan on Apr 07, 2009 3:51 AM

# re: Adding a New Survey to SharePoint w/ Alerts and Custom Permissions
Requesting Gravatar...
add the permissions, then add the alerts using the SharePoint Object Model:
Left by moss on Sep 25, 2010 1:28 PM

# re: Adding a New Survey to SharePoint w/ Alerts and Custom Permissions
Requesting Gravatar...
The second part dealt with some custom code that I wrote against this custom survey template.
Left by moss on Sep 25, 2010 1:30 PM

Your comment:
 (will show your gravatar)


Copyright © MOSSLover | Powered by: GeeksWithBlogs.net