Exemple #1
0
        /// <summary>
        /// Approves and publishes all assets referred in any link fields (such as URL or Summary Links), rich-text content and rich-text web parts.
        /// </summary>
        /// <param name="adapter">Data access adapter of the list item.</param>
        /// <param name="additionalFields">Internal name of fields where its HTML content need to be parsed.</param>
        public static void PublishRelatedAssets(ISPListItemAdapter adapter, params string[] additionalFields)
        {
            CommonHelper.ConfirmNotNull(adapter, "adapter");
            CommonHelper.ConfirmNotNull(additionalFields, "additionalFields");

            SPListItem item = adapter.ListItem;

            if (item != null)
            {
                using (SPItemEventHelper.GetEventFiringDisabledScope()) {
                    try {
                        foreach (SPField field in item.Fields)
                        {
                            try {
                                object value = item[field.Id];
                                if (value != null)
                                {
                                    if (additionalFields.Contains(field.StaticName))
                                    {
                                        PublishAssetFromHtml(value.ToString(), item);
                                    }
                                    else if (field is BaseRichFieldType)
                                    {
                                        PublishAssetFromHtml(value.ToString(), item);
                                    }
                                    else if (field is SPFieldUrl)
                                    {
                                        PublishAssetInternal(new SPFieldUrlValue(value.ToString()).Url, item);
                                    }
                                    else if (field is SummaryLinkField)
                                    {
                                        foreach (SummaryLink link in new SummaryLinkFieldValue(value.ToString()).SummaryLinks)
                                        {
                                            PublishAssetInternal(link.LinkUrl, item);
                                        }
                                    }
                                }
                            } catch {
                            }
                        }
                        if (item.File != null && item.File.Name.EndsWith(".aspx"))
                        {
                            using (SPLimitedWebPartManager wpm = item.File.GetLimitedWebPartManager(PersonalizationScope.Shared)) {
                                foreach (object wp in wpm.WebParts)
                                {
                                    if (wp is ContentEditorWebPart)
                                    {
                                        XmlElement elm = ((ContentEditorWebPart)wp).Content;
                                        if (elm != null)
                                        {
                                            PublishAssetFromHtml(elm.InnerText, item);
                                        }
                                    }
                                    else if (wp is ImageWebPart)
                                    {
                                        PublishAssetInternal(((ImageWebPart)wp).ImageLink, item);
                                    }
                                    else if (wp is MediaWebPart)
                                    {
                                        PublishAssetInternal(((MediaWebPart)wp).MediaSource, item);
                                    }
                                    else if (wp is SummaryLinkWebPart)
                                    {
                                        foreach (SummaryLink link in ((SummaryLinkWebPart)wp).SummaryLinkValue.SummaryLinks)
                                        {
                                            PublishAssetInternal(link.LinkUrl, item);
                                        }
                                    }
                                }
                            }
                        }
                    } catch (Exception ex) {
                        throw new Exception("Aborting approval because of some related contents cannot be published or approved", ex);
                    }
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Disables event firing on subsequent updates to list items until disposing the returned object.
 /// </summary>
 /// <returns>A disposable object.</returns>
 public IDisposable GetEventFiringDisabledScope()
 {
     return(SPItemEventHelper.GetEventFiringDisabledScope());
 }