Skip to main content

public override void ItemAdded(SPItemEventProperties properties) { if (properties.ListTitle == "Architecture Calendar") {

        public override void ItemAdded(SPItemEventProperties properties)
        {
            if (properties.ListTitle == "Architecture Calendar")
            {

                base.ItemAdded(properties);
                string eventUrl = null;
                string AttachUrl=null;

                using (SPSite site = properties.OpenSite())
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        try
                        {
                            SPList listCalendar = web.Lists[properties.ListId];
                            SPItem itemCalendar = properties.ListItem;
                            SPSite mainSite = new SPSite(site.Url + @"/admin/");
                            SPWeb mainWeb = mainSite.OpenWeb();
                            
                            **AttachUrl = properties.ListItem.Attachments.UrlPrefix + properties.ListItem.Attachments[0];**

                            SPList listIntegrated = mainWeb.Lists["IntegratedEvents"];
                            SPListItem itemIntegrated = listIntegrated.Items.Add();

                            **itemIntegrated["Picture"] = AttachUrl;**
                           
                            

                            itemIntegrated.Update();
                            

                        }
                        catch (Exception Ex)
                        {
                            throw Ex;
                        }
                    }
                }
            }

public override void ItemAdded(SPItemEventProperties properties) { if (properties.ListTitle == "Architecture Calendar") {

            base.ItemAdded(properties);
            string eventUrl = null;
            string AttachUrl=null;

            using (SPSite site = properties.OpenSite())
            {
                using (SPWeb web = site.OpenWeb())
                {
                    try
                    {
                        SPList listCalendar = web.Lists[properties.ListId];
                        SPItem itemCalendar = properties.ListItem;
                        SPSite mainSite = new SPSite(site.Url + @"/admin/");
                        SPWeb mainWeb = mainSite.OpenWeb();
                        
                        **AttachUrl = properties.ListItem.Attachments.UrlPrefix + properties.ListItem.Attachments[0];**

                        SPList listIntegrated = mainWeb.Lists["IntegratedEvents"];
                        SPListItem itemIntegrated = listIntegrated.Items.Add();

                        **itemIntegrated["Picture"] = AttachUrl;**
                       
                        

                        itemIntegrated.Update();
                        

                    }
                    catch (Exception Ex)
                    {
                        throw Ex;
                    }
                }
            }
        }
        public override void ItemAdded(SPItemEventProperties properties)
        {
            if (properties.ListTitle == "Architecture Calendar")
            {

                base.ItemAdded(properties);
                string eventUrl = null;
                string AttachUrl=null;

                using (SPSite site = properties.OpenSite())
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        try
                        {
                            SPList listCalendar = web.Lists[properties.ListId];
                            SPItem itemCalendar = properties.ListItem;
                            SPSite mainSite = new SPSite(site.Url + @"/admin/");
                            SPWeb mainWeb = mainSite.OpenWeb();
                            
                            **AttachUrl = properties.ListItem.Attachments.UrlPrefix + properties.ListItem.Attachments[0];**

                            SPList listIntegrated = mainWeb.Lists["IntegratedEvents"];
                            SPListItem itemIntegrated = listIntegrated.Items.Add();

                            **itemIntegrated["Picture"] = AttachUrl;**
                           
                            

                            itemIntegrated.Update();
                            

                        }
                        catch (Exception Ex)
                        {
                            throw Ex;
                        }
                    }
                }
            }
Source Link
suma
  • 11
  • 1

I have used the following code in an itemAdded event receiver.

public override void ItemAdded(SPItemEventProperties properties) { if (properties.ListTitle == "Architecture Calendar") {

            base.ItemAdded(properties);
            string eventUrl = null;
            string AttachUrl=null;

            using (SPSite site = properties.OpenSite())
            {
                using (SPWeb web = site.OpenWeb())
                {
                    try
                    {
                        SPList listCalendar = web.Lists[properties.ListId];
                        SPItem itemCalendar = properties.ListItem;
                        SPSite mainSite = new SPSite(site.Url + @"/admin/");
                        SPWeb mainWeb = mainSite.OpenWeb();
                        
                        **AttachUrl = properties.ListItem.Attachments.UrlPrefix + properties.ListItem.Attachments[0];**

                        SPList listIntegrated = mainWeb.Lists["IntegratedEvents"];
                        SPListItem itemIntegrated = listIntegrated.Items.Add();

                        **itemIntegrated["Picture"] = AttachUrl;**
                       
                        

                        itemIntegrated.Update();
                        

                    }
                    catch (Exception Ex)
                    {
                        throw Ex;
                    }
                }
            }
        }