SharePoint 2007 (MOSS/WSS) - Programmatically modifying the incoming email setting for Document Libraries

Requirement: I want to access and modify all the options given in Incoming Email setting page of Document Library programmatically.

 

pic

 

Here is the code of a Web Part for the same:

using System;

using System.Runtime.InteropServices;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Serialization;

using Microsoft.SharePoint;

using Microsoft.SharePoint.WebControls;

using Microsoft.SharePoint.WebPartPages;

namespace WPDocLibEmailSetting

{

[Guid("b5ddfbff-afbb-42bb-b4ea-3e3788ad0297")]

public class WPDocLibEmailSetting : System.Web.UI.WebControls.WebParts.WebPart

{

TextBox myText;

Button myBtn;

public WPDocLibEmailSetting()

{

}

protected override void CreateChildControls()

{

base.CreateChildControls();

myText = new TextBox();

myBtn = new Button();

myBtn.Text = "Submit";

myBtn.Click += new EventHandler(myBtn_Click);

this.Controls.Add(myText);

this.Controls.Add(myBtn);

}

void myBtn_Click(object sender, EventArgs e)

{

SPWeb site = SPContext.Current.Web;

Guid newListGuid = site.Lists.Add(myText.Text, myText.Text, SPListTemplateType.DocumentLibrary);

SPList newList = site.Lists[newListGuid];

newList.ContentTypesEnabled = true;

newList.OnQuickLaunch = true;

newList.EnableAssignToEmail = true;

newList.EmailAlias = myText.Text;

newList.Update();

newList.RootFolder.Properties["vti_emailattachmentfolders"] = "sender";

//Group attachments in folders, options: "subject"/"sender"/"root"

newList.RootFolder.Properties["vti_emailoverwrite"] = 0;

//Overwrite files with the same name, options 1/0

newList.RootFolder.Properties["vti_emailsaveoriginal"] = 1;

//Save original e-mail, options 1/0

newList.RootFolder.Properties["vti_emailsavemeetings"] = 0;

//Save meeting invitations, options 1/0

newList.RootFolder.Properties["vti_emailusesecurity"] = 1;

//Email Security Policy, options 1/0

newList.RootFolder.Update();

}

protected override void Render(HtmlTextWriter writer)

{

//base.Render(writer);

EnsureChildControls();

myText.RenderControl(writer);

myBtn.RenderControl(writer);

}

}

}