News

Events
About Me:
I am a 26 year old female SharePoint Enthusiast. I work for B&R Business Solutions from my home in Olathe, KS. 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 MOSS, attending Code Camps as a speaker, 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.

Rebecca Isserman's Facebook profile

My Stats

  • Posts - 201
  • Comments - 250
  • Trackbacks - 0

Twitter












Tag Cloud


Recent Comments


Recent Posts


Archives


Post Categories


B&R Blogs


Kansas City Community Blogs


Other Blogs


SharePoint Blogs



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 @ Thursday, February 21, 2008 1:22 PM | Filed Under [ MOSS ]

Comments

Gravatar # re: Adding a New Survey to SharePoint w/ Alerts and Custom Permissions
Posted by Dipanjan on 4/7/2009 3:51 AM
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
Gravatar # re: Adding a New Survey to SharePoint w/ Alerts and Custom Permissions
Posted by nike shoes new on 10/20/2009 3:04 AM
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
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: