예제 #1
0
 public override void OnUpdated()
 {
     try
     {
         FieldManagement <ImageFieldProperties> .SetFieldProperties(this);
     }
     catch (Exception)
     {
     }
 }
예제 #2
0
        public override void OnAdded(SPAddFieldOptions op)
        {
            //var data = FieldManagement<ImageFieldProperties>.GetFieldProperties(this);


            //if(string.IsNullOrEmpty(data.WebId)){
            //    data.WebId = SPContext.Current.Site.RootWeb.ID.ToString();
            //}
            try
            {
                FieldManagement <ImageFieldProperties> .SetFieldProperties(this);
            }
            catch (Exception ex)
            {
                Utility.LogError(ex);
            }
        }
예제 #3
0
        /// <summary>
        /// Create child controls
        /// </summary>
        protected override void CreateChildControls()
        {
            // Retrieve field properties

            fieldProperties = FieldManagement <ImageFieldProperties> .GetFieldProperties(this.Field);

            if (string.IsNullOrEmpty(fieldProperties.WebId))
            {
                fieldProperties.WebId = SPContext.Current.Web.ID.ToString();
            }
            if (ControlMode != SPControlMode.Display)
            {
                base.CreateChildControls();
                BindControls();

                if (ddlExistingPicture != null)
                {
                    if (!Page.IsPostBack)
                    {
                        // Retrieve all pictures in order to add them in the drop down list
                        using (SPWeb web = SPContext.Current.Site.OpenWeb(new Guid(fieldProperties.WebId)))
                        {
                            if (!fieldProperties.PictureLibraryId.IsGuid())
                            {
                                var folder = web.Folders[fieldProperties.PictureLibraryId];
                                var list   = web.Lists[folder.ParentListId];
                                fieldProperties.PictureLibraryId = list.ID.ToString();
                            }
                            SPList pictureLibrary         = web.Lists[new Guid(fieldProperties.PictureLibraryId)];
                            SPListItemCollection pictures = pictureLibrary.GetItems(new SPQuery {
                                Query = "<Query />"
                            });

                            if (fieldProperties.DefaultPictureId != -1)
                            {
                                ddlExistingPicture.Items.Add(new ListItem(SPUtility.GetLocalizedString("$Resources:Default", "ImageField", (uint)SPContext.Current.Web.Locale.LCID), fieldProperties.DefaultPictureId.ToString()));
                            }

                            ddlExistingPicture.Items.Add(new ListItem(SPUtility.GetLocalizedString("$Resources:None", "ImageField", (uint)SPContext.Current.Web.Locale.LCID), "-1"));
                            imgExistingPicture.Visible = false;

                            foreach (SPListItem picture in pictures)
                            {
                                if (!picture.Name.StartsWith("dv_") || picture.Name.Length != 39)
                                {
                                    string   pictureUrl  = Utility.GetRelativeUrl(picture["EncodedAbsThumbnailUrl"].ToString());
                                    ListItem pictureItem = new ListItem(picture.Name, picture.ID.ToString());

                                    // If the picture is the one referenced by the field
                                    if (this.ControlMode == SPControlMode.Edit && this.ItemFieldValue != null && new FieldContent(this.ItemFieldValue.ToString()).Thumbnail == pictureUrl)
                                    {
                                        pictureItem.Selected        = true;
                                        imgExistingPicture.Visible  = true;
                                        imgExistingPicture.ImageUrl = pictureUrl;
                                    }

                                    ddlExistingPicture.Items.Add(pictureItem);
                                }
                            }
                            if (imgExistingPicture.Visible == false)
                            {
                                ddlExistingPicture_OnSelectedIndexChanged(null, null);
                            }
                        }
                    }

                    ddlExistingPicture.SelectedIndexChanged += ddlExistingPicture_OnSelectedIndexChanged;
                }
            }
        }