More in this section

Forums / General Discussions / Custom Field

Custom Field

4 posts, 0 answered
  1. Rafael
    Rafael avatar
    19 posts
    Registered:
    29 Jul 2011
    17 Aug 2011
    Link to this post
    Hi,

    Now i just start work with sitefinity and i need add a custom image o use a defult one in a post! But the difficult is that i have to create a custom field because the image don't has in the "body" of the post. the image has be in the head of the post.

    Can help me someone?

    Thanks and regards.

    Ing. Monaco
  2. Rafael
    Rafael avatar
    19 posts
    Registered:
    29 Jul 2011
    18 Aug 2011
    Link to this post
    I could create a field but now when i can't create an intances in the DB.

    In my module i have this:

    In LegislationManager:

    ContentLinksExtensions.CopyContentLink("LegislationImage", source, destination);

    In LegislationsDefinitions:

    var legislationImageField = new ImageFieldElement(mainSection.Fields)
                {
                    ID = "avatarField",
                    DataFieldName = "LegislationImage",
                    DisplayMode = displayMode,
                    UploadMode = ImageFieldUploadMode.Dialog,
                    Title = "LegislationImage",
                    WrapperTag = HtmlTextWriterTag.Li,
                    CssClass = "sfUserAvatar",
                    ResourceClassId = typeof(LegislationsResources).Name,
                    DataFieldType = typeof(ContentLink),
                    DefaultSrc = "~/SFRes/images/CCG.ContentTypes.Legislations/Images.NoLegislationImage.png",// put your default image location example: 
                    SizeInPx = 100
                };
                mainSection.Fields.Add(legislationImageField);

    In LegislationsResource:

    [ResourceEntry("LegislationImageFieldTitle",
                Value = "Legislation image",
                Description = "phrase:  Legislation Image Field title",
                LastModified = "2011/15/06")]
            public string LegislationImageFieldTitle
            {
                get { return this["LegislationImageFieldTitle"]; }
            }

    And Finally in LegislationsModule:

    if (!type.Fields.ToList().Any(fld => fld.FieldName == "LegislationImage"))
                {
                    type.Fields.Add(ContentLinksExtensions.CreateContentLinkField("LegislationImage", "OpenAccessDataProvider", metaMan, RelationshipType.OneToOne));
                }

    I just add a pic with the problem.

    Thanks and Regards.
  3. Rafael
    Rafael avatar
    19 posts
    Registered:
    29 Jul 2011
    18 Aug 2011
    Link to this post
    I can fix this problem, now i have this Error.

  4. Rafael
    Rafael avatar
    19 posts
    Registered:
    29 Jul 2011
    18 Aug 2011
    Link to this post
    i just fix the problem! thanks
4 posts, 0 answered