FileFieldDefinitionElement?
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);
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 );
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
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
Hi Jocelyn,
I set Telerik.Sitefinity.Libraries.Model.Image for thumbnail field.
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!
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
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.
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.
Parameter name: key
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
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);