Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Event receiver when form added to library(Item added)..

$
0
0

I am looking to deploy the event receiver code below which should perform a re link documents when user adds a form to the form library and same way when user updates the form event should perform re link.How can i attach a worker process and check whether the event receiver and the code below is performing the required re link functionality.I am not able to understand whether the event is firing when the form is getting added to form library..Please help me

public override void ItemAdded(SPItemEventProperties properties)
       {

base.ItemAdded(properties);

           SPListItem spItem = properties.ListItem;
            SPList list = spItem.ParentList;
            SPWeb oWebURL = list.ParentWeb;
            SPDocumentLibrary doclib = (SPDocumentLibrary)list;
             string solutionUrl = SPHttpUtility.UrlPathEncode(oWebURL + "/" + doclib.DocumentTemplateUrl, true);

            SPFieldCollection spFields = spItem.Fields;

            foreach (SPField spField in spFields) //loop through fields resetting them
            {
                if (spField.Type != SPFieldType.Computed &&
                spField.Type != SPFieldType.Invalid && !spField.ReadOnlyField)
                {
                    try
                    {
                        spItem[spField.InternalName] = spItem[spField.InternalName];
                    }
                    catch (Exception e)
                    {
                    }
                }
            }
            SPContentType spContentType = list.ContentTypes[(SPContentTypeId)spItem["ContentTypeId"]];
                            if (spContentType != null) //try to update the item with the content type's template url which is the updated one
                            {
                                if (spContentType.DocumentTemplate.StartsWith("http://") ||
                                spContentType.DocumentTemplate.StartsWith("https://"))
                                {
                                    spItem["TemplateUrl"] = SPHttpUtility.UrlPathEncode(spContentType.DocumentTemplate, true);
                                }
                                else if (spContentType.DocumentTemplate.StartsWith("/"))
                                {
                                    spItem["TemplateUrl"] = SPHttpUtility.UrlPathEncode(oWebURL.Site.MakeFullUrl(spContentType.DocumentTemplate), true);
                                }
                                else
                                {
                                    spItem["TemplateUrl"] = SPHttpUtility.UrlPathEncode(oWebURL.Url + '/' + list.RootFolder + '/' + spContentType.DocumentTemplate, true);
                                }
                            }
                            else //no content type found so default template url to solution Url
                            {
                                spItem["TemplateUrl"] = solutionUrl;
                            }
                            spItem.Update();
                           

                        }


    

                
            
            
       

       /// <summary>
       /// An item was updated.
       /// </summary>
       public override void ItemUpdated(SPItemEventProperties properties)
       {
           base.ItemUpdated(properties);
       }



Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>