Welcome to MSDN Blogs Sign in | Join | Help

Pranab Paul's Blog - SharePoint 2007 (MOSS/WSS 3.0) Development Tips

------------------------------------------Web Parts, Workflow, InfoPath Form Services, Features, Site Definition, Event Receivers, Excel Services, Business Data Catalog (BDC), Search

News

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);

        }

    }

}

 

Comments

colinbo said:

A call to Update is resulting in a very opaque error being thrown:

Microsoft.SharePoint.SPException: Error in the application.

  at Microsoft.SharePoint.SPList.UpdateDirectoryManagementService(String oldAlias, String newAlias)

  at Microsoft.SharePoint.SPList.Update(Boolean bFromMigration)

  at Microsoft.SharePoint.SPList.Update()

Any thoughts?

Write-Host "Enabling Email Archiving";

$DiscussionsList = $ClientWeb.Lists["Discussions"];

$DiscussionsList.EmailAlias = $LowerDomainNameWithoutSuffix + "-archive";

$DiscussionsList.ContentTypesEnabled = $true;

$DiscussionsList.Update();

$RootFolder = $DiscussionsList.RootFolder;

$RootFolder.Properties["vti_emailsaveattachments"] = 1;

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

$RootFolder.Properties["vti_emailsaveoriginal"] = 0;

$RootFolder.Properties["vti_emailusesecurity"] = 0;

$RootFolder.Update();

# June 18, 2008 12:48 PM

sarita said:

I have the same problem. Whenever I try to set the EmailAlias property and then to update() the list, the update failes and results with the following exception:

Microsoft.SharePoint.SPException: Error in the Application.

 at Microsoft.SharePoint.SPList.UpdateDirectoryManagementService(String oldAlias, String newAlias)

 at Microsoft.SharePoint.SPList.Update(Boolean bFromMigration)

 at Microsoft.SharePoint.SPList.Update()

I'm using the same code as the above:

newList.EmailAlias = "test";

newList.Update();

Does anyone have an idea what is the reason for this?

Thanks.

# July 28, 2008 4:22 AM

obonnate said:

I had the same problem (Application Error). It turned out that I was using the administrator account to launch my script and this account had not the appropriate rights on the portal.

Once I opened my power shell console with an account authorized on the portal, the script worked.

# August 14, 2008 5:52 AM

JMSAM said:

Which  are those "appropiate rights on the portal"?

Thanks in advance!

jm.sanagerico@layetana.com

# April 22, 2009 4:40 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker