Creating email enabled document library programatically

public const string InboxLibrary = “Inbox”;
public const string EmailAttachmentFolders = “vti_emailattachmentfolders”;
public const string EmailOverwrite = “vti_emailoverwrite”;
public const string EmailSaveOriginal = “vti_emailsaveoriginal”;
public const string EmailSaveMeetings = “vti_emailsavemeetings”;
public const string EmailUseSecurity = “vti_emailusesecurity”;
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
using (SPWeb rootweb = properties.Feature.Parent as SPWeb)
{
SPList inboxList = rootweb.Lists[Constants.InboxLibrary];
inboxList.EnableAssignToEmail = true;
inboxList.EmailAlias = Constants.InboxLibrary;
inboxList.Update();
inboxList.RootFolder.Properties[Constants.EmailAttachmentFolders] = “sender”;
inboxList.RootFolder.Properties[Constants.EmailOverwrite] = 0;
inboxList.RootFolder.Properties[Constants.EmailSaveOriginal] = 0;
inboxList.RootFolder.Properties[Constants.EmailSaveMeetings] = 0;
inboxList.RootFolder.Properties[Constants.EmailUseSecurity] = 1;
inboxList.RootFolder.Update();
}
}

As you know SharePoint allows the creation of document libraries and lists allowing to have their own email address to receive files to. After initial configuration in SharePoint Central Admin it`s pretty much less than a minute to configure document library to receive email; in case you need to perform this configuration programatically depending on some action use the code below:

public const string InboxLibrary = “Inbox”;

public const string EmailAttachmentFolders = “vti_emailattachmentfolders”;

public const string EmailOverwrite = “vti_emailoverwrite”;

public const string EmailSaveOriginal = “vti_emailsaveoriginal”;

public const string EmailSaveMeetings = “vti_emailsavemeetings”;

public const string EmailUseSecurity = “vti_emailusesecurity”;

public override void FeatureActivated(SPFeatureReceiverProperties properties)

{

using (SPWeb rootweb = properties.Feature.Parent as SPWeb)

{

SPList inboxList = rootweb.Lists[Constants.InboxLibrary];

inboxList.EnableAssignToEmail = true;

inboxList.EmailAlias = Constants.InboxLibrary;

inboxList.Update();

inboxList.RootFolder.Properties[Constants.EmailAttachmentFolders] = “sender”;

inboxList.RootFolder.Properties[Constants.EmailOverwrite] = 0;

inboxList.RootFolder.Properties[Constants.EmailSaveOriginal] = 0;

inboxList.RootFolder.Properties[Constants.EmailSaveMeetings] = 0;

inboxList.RootFolder.Properties[Constants.EmailUseSecurity] = 1;

inboxList.RootFolder.Update();

}

}

In my case, I have FeatureActivated method which will enable email on a document Inbox library depending on a web where the feature was activated under.

This entry was posted in MOSS, sharepoint and tagged , , . Bookmark the permalink.

Comments are closed.