Introduction
File Management mentioned in the article is a component implemented in RapidWebDev, which is designed to save the effort on developing file-required systems through its easy APIs and integration with ASP.NET web development, e.g. a product requires attachments and thumbnails in a product management system. You shall have basic impression from the following 4 minutes video on WHAT. Then the article introduces the data model, APIs and ASP.NET web control in detail.
Please click the screenshot of the Flash video below to watch it in the popup window.
Data Model
There are only 2 data tables for file management in RapidWebDev v1.52:
fm_Files: The table is used to store file head information only. The file stream is managed by the implementation of IFileStorageApi
in file management component. There is a default implementation to store files in shared path.
Column | Type | Comment |
FileId | uniqueidentifier | The auto generated id of a file |
ApplicationId | uniqueidentifier | The SaaS application id which the file belongs to. RapidWebDev is a SaaS compatible solution. |
Category | nvarchar(31) | The category of the file |
Name | nvarchar(255) | The file name with extension name.e.g. thumbnail.jpg |
ExtensionName | nvarchar(15) | The file extension name without dot. e.g. jpg |
Description | ntext | The file description |
BytesCount | bigint | The file size in bytes |
CreatedOn | datetime | The date time when the file is created |
UpdatedOn | datetime | The date time when the file is last updated |
Version | int | The version number of the file which starts from 1. We keep potential to support file versioning in the future. |
fm_FileBindings: The table is used to show the relationship between file and external objects.
Column | Type | Comment |
ApplicationId | uniqueidentifier | The SaaS application id which the relationship belongs to. RapidWebDev is a SaaS compatible solution. |
ExternalObjectId | uniqueidentifier | ID of any business objects which need file support. Like when you're developing a product management system with attachments and thumbnails support, the ProductId should be the external object id; when you're developing order system with attachments support, the OrderId should be the external object id. |
FileId | uniqueidentifier | The id the file stored in data table fm_Files |
RelationshipType | nvarchar(64) | the relationship type between external objects and files. Like when you're developing a product management system with attachments and thumbnails support, there should be 2 relationship types "Attachment " and "Thumbnail " between files and a product. |
Internal APIs
There are only two interfaces for developers usually, IFileManagementApi
and IFileBindingApi
. The former one is used to manage file information and the latter one is used to manage relationship between files and external objects. In the following code snippet, the article ignores overload methods.
public interface IFileManagementApi
{
FileHeadObject Save(FileUploadObject fileUploadObject);
void Delete(Guid fileId);
FileHeadObject Load(Guid fileId);
}
public interface IFileBindingApi
{
void Bind(string relationshipType, Guid externalObjectId, Guid fileId);
void Unbind(Guid externalObjectId, string relationshipType);
void DeleteBoundFiles(Guid externalObjectId);
IEnumerable<FileHeadObject> FindBoundFiles
(Guid externalObjectId, string relationshipType);
}
ASP.NET Web Control
FileManagementControl
is used to manage related files to a business object which locates at \\RapidWebDev.FileManagement\Web\FileManagementControl.cs. The control has the following properties:
Property | PropertyType | Comment |
Uploadable | bool | True when the control is allowed to upload new files, defaults to True . |
Deletable | bool | True when the control is allowed to delete existed files, defaults to True . |
ReadOnly | bool | True when the control is readonly which cannot either upload new files or delete existed files, defaults to False . |
MultipleUpload | bool | True when the control supports to upload multiple files, defaults to True . |
MaximumFileCount | int | Maximum files can be managed by the control, defaults to 10 . The property is useless when the property MultipleUpload equals to False . |
FileCategory | string | Category of the managed files by the control, defaults to null . |
EnableFileRemove<br />Confirmation | bool | Whether to show confirmation dialog for file removal, defaults to False . |
FileUploadDialogTitle | string | Title of file uploading dialog, defaults to the globalized message "Resources.FileUploadDialogTitle ". |
RelationshipType | string | The relationship type between the external object and managing files, which will be saved into the table fm_FileBindings . |
ExternalObjectId | Guid | Sets/gets the external object id which the managing files are associated with. |
A sample code below demonstrates how to use the control:
<My:FileManagementControl ID="ProductAttachments"
FileCategory="ProductAttachment"
RelationshipType="Attachment" runat="server" />
void ButtonLoad_Click(object sender, EventArgs e)
{
this.ProductAttachments.ExternalObjectId = ??;
}
void ButtonSave_Click(object sender, EventArgs e)
{
int associatedFileCount = this.ProductAttachments.AssociatedFileCount;
this.ProductAttachments.ExternalObjectId = ??;
this.ProductAttachments.Save();
}
Permission Integration
FileManagement
integrates with permission through the interface IPermissionBridge
in both HTTP file upload/download handler and FileManagementControl
. There are three file operation permissions, Upload, Delete and Download. FileManagementControl
renders Upload and Delete depending on whether the user has the related permission. HTTP file upload/download handler does the same. The permission value of file operation follows the format below:
Upload
: FileManagement.{FileCategory}.Upload
Delete
: FileManagement.{FileCategory}.Delete
Download
: FileManagement.{FileCategory}.Download
interface IPermissionBridge
{
bool HasPermission(string permissionValue);
}
What's RapidWebDev
Official Website for download: http://www.rapidwebdev.org
RapidWebDev is an infrastructure helps engineers to develop enterprise software solutions in Microsoft .NET easily and productively. It consists of an extendable and maintainable web system architecture with a suite of generic business model, APIs and services as fundamental functionalities needed in development for almost all business solutions. So when engineers develop solutions in RapidWebDev, they can have a lot of reusable and ready things then they can more focus on business logics implementation. In practice, we can save more than 50% time on developing a high quality and performance business solution than direct ASP.NET coding.