setting incoming email settings of discussion forum list in sharepoint programmatically

hi,

 i was told to set the incoming email settings of  discussion forum list in sharepoint programmatically,so i was able to get this done with the below code:

It will take the  subsite’s name and add it with the email settings [alias] of our discussion forum list’s incoming email settings section:

private void GetListofDiscForumLists(SPWebCollection selNodewebCollec)
      {
          string restrictedFolderName = “Restricted”;
          string non_restrictedFolderName = “Non-Restricted”;

          try
          {
              foreach (SPWeb singleWeb in selNodewebCollec)
              {
                  if (singleWeb != null)
                  {
                      singleWeb.AllowUnsafeUpdates = true;

                      string singleweburl = singleWeb.Url;

                      using (SPSite objchildsite = new SPSite(singleWeb.Url))
                      {
                          using (SPWeb objchildweb = objchildsite.OpenWeb())
                          {
                              objchildweb.AllowUnsafeUpdates = true;
                              string objchildsweburl = objchildweb.Url;
                              if (objchildweb.Lists.Count > 0)
                              {
                                  for (int iListCount = objchildweb.Lists.Count – 1; iListCount > 0; iListCount–)
                                  {
                                      SPList singleDisclist = objchildweb.Lists[iListCount];

                                      if (singleDisclist.BaseTemplate == SPListTemplateType.DiscussionBoard)
                                      {
                                          SPList tempDiscForumList = singleDisclist;

                                          if (singleDisclist.CanReceiveEmail)
                                          {
                                              singleDisclist.EnableAssignToEmail = true;
                                              singleDisclist.EmailAlias = Regex.Replace(“Exp_”+objchildweb.Title, @”[^0-9a-z]”, “”, RegexOptions.IgnoreCase);
                                              SPFolder rootFolder = singleDisclist.RootFolder;
                                              rootFolder.Properties[“vti_emailusesecurity”] = 0;
                                              rootFolder.Properties[“vti_emailsaveattachments”] = 1;
                                              rootFolder.Properties[“vti_emailattachmentfolders”] = “subject”;
                                              rootFolder.Properties[“vti_emailoverwrite”] = 0;
                                              rootFolder.Properties[“vti_emailsavemeetings”] = 0;
                                              rootFolder.Properties[“vti_emailsaveoriginal”] = 1;
                                              rootFolder.Update();
                                              singleDisclist.Update();
                                          }
                                          else
                                          {
                                              throw new SPException(string.Format(“‘{0}’ can not receive mail”, singleDisclist));
                                          }
                                      }
                                  }
                              }
                              objchildweb.AllowUnsafeUpdates = false;
                          }
                      }
                      if (singleWeb.Webs.Count > 0)
                      {
                          GetListofDiscForumLists(singleWeb.Webs);
                      }
                  }

                  singleWeb.AllowUnsafeUpdates = false;
              }
          }
          catch (Exception expppo)
          {
              throw;
          }
     

hope this helps someone!

happy SharePointing!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s