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