FileFieldDefinitionElement?

Posted by Community Admin on 03-Aug-2018 21:46

FileFieldDefinitionElement?

All Replies

Posted by Community Admin on 24-Jan-2011 00:00

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);

Posted by Community Admin on 25-Jan-2011 00:00

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

Posted by Community Admin on 26-Jan-2011 00:00

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

Posted by Community Admin on 26-Jan-2011 00:00

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

Posted by Community Admin on 26-Jan-2011 00:00

Hi Jocelyn,
I set  Telerik.Sitefinity.Libraries.Model.Image for thumbnail field.

Posted by Community Admin on 13-Jul-2011 00:00

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!

Posted by Community Admin on 14-Jul-2011 00:00

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

Posted by Community Admin on 14-Jul-2011 00:00

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

Posted by Community Admin on 19-Jul-2011 00:00

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

This thread is closed