time cockpit supports file attachments to database rows. To store the file's content and metadata you have to extend your model (see also HowTo: Modifying The Model). In this chapter we will cover details about how to add a file property to your model and how to use it from within lists and forms.
Dieses Thema enthält die folgenden Abschnitte.
Adding the Property
TimeCockpit.Data.DataModel..::..FileProperty implements the property holding the file's content. In order to work properly in the user interface you have to create additional properties that store the file's name (FileNameColumn), the MIME type (FileMimeTypeColumn) and the file's size (FileSizeColumn).
The following example shows how to add a file property to the entity contactEntity:
# Avatar File Name fileNameProperty = TextProperty({ "Name": "USR_AvatarFileName", "InvariantFriendlyName":"Avatar File Name", "MaxStorageSize" : 256, "IsNullable" : True, "IsDefaultDisplayProperty" : False, "DefaultValueExpression" : "\"\"", "Ownership" : Ownership.User }) contactEntity.Properties.Add(fileNameProperty) # Avatar File Mime Type mimeTypeProperty = TextProperty({ "Name": "USR_AvatarMimeType", "InvariantFriendlyName":"Avatar Mime Type", "MaxStorageSize" : 256, "IsNullable" : True, "IsDefaultDisplayProperty" : False, "DefaultValueExpression" : "\"\"", "Ownership" : Ownership.User }) contactEntity.Properties.Add(mimeTypeProperty) # Avatar File Size fileSizeProperty = NumericProperty({ "Name": "USR_AvatarFileSize", "InvariantFriendlyName":"Avatar File Size", "Precision" : 18, "Scale" : 0, "IsNullable" : True, "FormatPattern": "#,###", "IsDefaultDisplayProperty" : False, "DefaultValueExpression" : "0", "Ownership" : Ownership.User }) contactEntity.Properties.Add(fileSizeProperty) # Avatar file property. allowedMimeTypes = List[String]() allowedMimeTypes.Add("image/jpeg") allowedMimeTypes.Add("image/png") allowedExtensions = List[String]() allowedExtensions.Add(".png") allowedExtensions.Add(".jpeg") allowedExtensions.Add(".jpg") fileProperty = FileProperty({ "Name": "USR_Avatar", "InvariantFriendlyName": "Avatar", "FileNameColumn": "USR_AvatarFileName", "FileSizeColumn": "USR_AvatarFileSize", "FileMimeTypeColumn": "USR_AvatarMimeType", "MaxFileSizeInKB" : 128, "IsNullable" : True, "AllowedMimeTypes" : allowedMimeTypes, "AllowedExtensions" : allowedExtensions, "ContentProcessing": ContentProcessing.Compress }) contactEntity.Properties.Add(fileProperty)
Using the Property
You can use the TimeCockpit.Data.DataModel..::..FileProperty just like you use any other property type. You can add a TimeCockpit.Data.DataModel.View..::..BoundCell to your list and/or form and time cockpit will automatically discover that your property represents a file and will display it appropriately (e.g. if it is an image it will display the image in the list). If you want more control over how the file property is displayed in your list or form use TimeCockpit.Data.DataModel.View..::..FileCell instead of TimeCockpit.Data.DataModel.View..::..BoundCell.
The following example uses a TimeCockpit.Data.DataModel.View..::..BoundCell to display the file property USR_Avatar.
<List AllowDelete="True" AllowEdit="True" Query="From I In USR_Contact.Include(*) Select I" xmlns="clr-namespace:TimeCockpit.Data.DataModel.View;assembly=TimeCockpit.Data"> <BoundCell Content="=Current.USR_Avatar" /> <BoundCell Content="=Current.USR_FirstName" /> <BoundCell Content="=Current.USR_LastName" /> </List>