Progress will discontinue Telerik Platform on May 10th, 2018. Learn more

Associating Files with Data Items

Associating Files with Data Items

If you have already uploaded a file and have its ID, you can assign it to a content type items as a value. The Telerik Platform portal automatically expands File IDs of pictures and displays a thumbnail in the details pane.

Create Associations

Creating association to a file is as simple as setting the desired file field value of the content type to be the ID of a file.

public async void CreateAssociation(EverliveApp app, Guid activityId, Guid pictureId)
{
    string typeName = "Activities";
    Activity updateObject = new Activity();
    updateObject.Picture = pictureId;
    await app.Items(typeName).UpdateByIdAsync(activityId, updateObject);
}

Remove Associations

Deleting an item from the database does not unlink it from the items that are associated with it. In order to remove the association an additional request has to be made.

Single Association

public void DeleteAssociation(EverliveApp app, Guid activityId)
    {
        Activity updateObject = new Activity();
        updateObject.Picture = Guid.Empty;
        app.WorkWith().Data().Update(activityId, updateObject).ExecuteSync();
    }

Note: Instead of using instance of Activity, you can use the UpdateObject class as shown here

All Associations

In order to delete all references to a given file you will need to make a request in the content type. The example below uses LINQ expression to filter the items associating the file. The same thing can be using any other filtering method described here

public void UpdateActivitiesByFilter(EverliveApp app, Guid pictureId)
{
    Activity updateObject = new Activity();
    updateObject.Picture = Guid.Empty;
    this.App.WorkWith().Data().Update(updateObject).Where(a => a.Picture == pictureId).ExecuteSync();
}
Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved.