1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / FileFieldDefinitionElement?

FileFieldDefinitionElement?

9 posts, 0 answered
  1. Saad
    Saad avatar
    98 posts
    Registered:
    10 Oct 2008
    24 Jan 2011
    Link to this post
    Hello,
    I am using definition element to upload an image file using FileFieldDefinitionElement. How can I have a dialog kind of element on my form so that user could select image from existing library(s) and could also upload new one?

    I used ImageFieldElement too, but it says that it has not been implemented yet.

    Here is my code:

    var thumbnailField = new FileFieldDefinitionElement(mainSection.Fields)
                {
                    ID = "thumbnailFieldControl",
                    DataFieldName = "Thumbnail",
                    DisplayMode = displayMode,
                    FieldType = typeof(FileField),
                    Title = "Saad",
                    CssClass = "sfTitleField",
                    IsMultiselect = false,
                    MaxFileCount = 1,
                    LibraryContentType = typeof(ImageField),
                    WrapperTag = HtmlTextWriterTag.Li
                };
                mainSection.Fields.Add(thumbnailField);


                detailView.Sections.Add(mainSection);
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    25 Jan 2011
    Link to this post
    Hi saadi,

    1. You should create a custom filed control that will open a selector that will allow you to choose an image. You should inherit from FiledControl class. You can find a sample code here.

    2. You should create a custom DefinitionElement that inherits from FieldControlDefinitionElement

    3. You should use your custom definition element in your module definition class

    var myField = newMyImageDefinitionElement(section.Fields)
    {
     ....
    };
     
    section.Fields.Add(myField );



    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Saad
    Saad avatar
    98 posts
    Registered:
    10 Oct 2008
    26 Jan 2011
    Link to this post
    Thanks Ivan, will I need to have both classes (one inherting from FieldControl, other from FieldControlDefinitionElement)?

    The sample code you mentioned is inheriting FieldControl. What does it have a relation with our definition element?
    Can I have a simple structure of the the class.

    Thanks
  4. jocelyn payneau
    jocelyn payneau avatar
    51 posts
    Registered:
    07 Dec 2009
    26 Jan 2011
    Link to this post
    Hello Saadi,

    For my project, I also need to have a file upload widget. I managed to place it on my form.

    But what is the data type for the "thumbnail" field?

    You declare it like any field?

    Thanks

    Jocelyn
  5. Saad
    Saad avatar
    98 posts
    Registered:
    10 Oct 2008
    26 Jan 2011
    Link to this post
    Hi Jocelyn,
    I set  Telerik.Sitefinity.Libraries.Model.Image for thumbnail field.
  6. Saeed
    Saeed avatar
    14 posts
    Registered:
    21 Jun 2011
    13 Jul 2011
    Link to this post
    Hi there,

    I already added ImageFieldElemnet to my entity, but how can I add Document Selector?

    I tried this:
    var downloadUrlField = new Telerik.Sitefinity.Web.UI.Fields.Config.FileFieldDefinitionElement(mainSection.Fields)
                {
                    ID = "downloadUrlFieldControl",
                    DataFieldName = (displayMode == FieldDisplayMode.Write) ? "DownloadUrl.PersistedValue" : "DownloadUrl",
                    Title = "DownloadUrl",
                    DisplayMode = displayMode,
                    CssClass = "sfFormSeparator sfContentField",
                    ResourceClassId = typeof(PressResources).Name,
                    WrapperTag = HtmlTextWriterTag.Li,
                    IsMultiselect = false,
                    MaxFileCount = 1,
                    LibraryContentType = ?,
                    FieldType = ?
                };
                mainSection.Fields.Add(downloadUrlField);

    But I don't know what should I put for LibraryContentType and FieldType there!

    Cheers,
    Saeed!
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    14 Jul 2011
    Link to this post
    Hi Saeed,

    LibraryContentType could be set to

    LibraryContentType = typeof(Image)
    LibraryContentType = typeof(Document)
    LibraryContentType = typeof(Video)


    FieldType could be set to

    FieldType = typeof(FileField)
    FieldType = typeof(ImageUploadField)
    FieldType = typeof(MediaField)


    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. Saeed
    Saeed avatar
    14 posts
    Registered:
    21 Jun 2011
    14 Jul 2011
    Link to this post
    Thanks Ivan,

    I'm using Multilingual String for DownloadUrl Field, and Added following Control:

    var downloadUrlField = new FileFieldDefinitionElement(mainSection.Fields)
                {
                    ID = "downloadUrlFieldControl",
                    DataFieldName = (displayMode == FieldDisplayMode.Write) ? "DownloadUrl.PersistedValue" : "DownloadUrl",
                    Title = "DownloadUrl",
                    DisplayMode = displayMode,
                    CssClass = "sfFormSeparator sfContentField",
                    ResourceClassId = typeof(PressResources).Name,
                    WrapperTag = HtmlTextWriterTag.Li,
                    IsMultiselect = false,
                    MaxFileCount = 1,
                    LibraryContentType = typeof(Telerik.Sitefinity.Libraries.Model.Document),
                    FieldType =  typeof(FileField)
                };

    But I got following error:

    Value cannot be null.
    Parameter name: key

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.ArgumentNullException: Value cannot be null.
    Parameter name: key

    Source Error: 

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace: 

    [ArgumentNullException: Value cannot be null.
    Parameter name: key]
       System.Collections.ObjectModel.KeyedCollection`2.Contains(TKey key) +475
       Telerik.Sitefinity.Localization.Res.Get(String classId, String key, CultureInfo culture, Boolean fallback, Boolean throws) +113
       Telerik.Sitefinity.Web.UI.Fields.FileField.Configure(IFieldDefinition definition) +129
       Telerik.Sitefinity.Web.UI.FieldFactory.GetFieldControl(IFieldDefinition definition) +274
       Telerik.Sitefinity.Web.UI.ContentUI.Views.Backend.Detail.SectionControl.FieldsRepeater_ItemDataBound(Object sender, RepeaterItemEventArgs e) +383
       System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem) +204
       System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource) +627
       System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) +167
       System.Web.UI.Control.DataBindChildren() +11339175
       System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +321
       System.Web.UI.Control.DataBindChildren() +11339175
       System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +321
       System.Web.UI.Control.DataBindChildren() +11339175
       System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +321
       System.Web.UI.Control.DataBindChildren() +11339175
       System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +321
       System.Web.UI.Control.DataBindChildren() +11339175
       System.Web.UI.Control.DataBindChildren() +11339175
       System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +321
       System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem) +185
       System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource) +627
       System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) +167
       Telerik.Sitefinity.Web.UI.ContentUI.Views.Backend.Detail.DetailFormView.OnPreRender(EventArgs e) +350
       System.Web.UI.Control.PreRenderRecursiveInternal() +113
       System.Web.UI.Control.PreRenderRecursiveInternal() +222
       System.Web.UI.Control.PreRenderRecursiveInternal() +222
       System.Web.UI.Control.PreRenderRecursiveInternal() +222
       System.Web.UI.Control.PreRenderRecursiveInternal() +222
       System.Web.UI.Control.PreRenderRecursiveInternal() +222
       System.Web.UI.Control.PreRenderRecursiveInternal() +222
       System.Web.UI.Control.PreRenderRecursiveInternal() +222
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4201
  9. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    Registered:
    18 Sep 2017
    19 Jul 2011
    Link to this post
    Hi Saeed,

    Here is the working definition.
    var downloadUrlField = new FileFieldDefinitionElement(mainSection.Fields)
               {
                   ID = "downloadUrlFieldControl",
                   Title = "DownloadUrl",
                   DataFieldName = "DownloadUrl",
                   DisplayMode = FieldDisplayMode.Read,
                   CssClass = "",
                   WrapperTag = HtmlTextWriterTag.Li,
                   FieldType = typeof(FileField),
                   LibraryContentType = typeof(Telerik.Sitefinity.Libraries.Model.Document),
                   ResourceClassId = typeof(ProductsResources).Name,
                    
                   ItemName = "DownloadUrl",
                   ItemNamePlural = "DownloadUrl",
                   IsMultiselect = false,
                   MaxFileCount = 1
               };
               mainSection.Fields.Add(downloadUrlField);
    With this you will get an option to open file, but this alone will not allow you to select a document. To select a document you must add the logic for the definition element similar to the image selector. Here is a tutorial. Note the file structure it includes FieldDefinition and FieldElement code files.

    Best wishes,
    Stanislav Velikov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
9 posts, 0 answered