private bool PopulateBodyPanelWithRelatedDownloads(Guid fileId, NavigationProperty navigationProperty) { bool success = false; List <File> relatedResources = null; IDictionary <Guid, IEnumerable <string> > userPermissions = null; if (this.DesignMode) { relatedResources = GetDesignTimeRelatedFiles(); } else { if (!IsSecurityAwareControl) { relatedResources = GetRelatedFiles(fileId, navigationProperty); } else { //If control is security aware the get resources as well as their respective user permissions. IEnumerable <ResourcePermissions <File> > resourcesWithPermissions = GetRelatedFiles(AuthenticatedToken, fileId, navigationProperty); if (resourcesWithPermissions != null) { relatedResources = resourcesWithPermissions.Select(tuple => tuple.Resource).ToList(); userPermissions = resourcesWithPermissions.ToDictionary(tuple => tuple.Resource.Id, tuple => tuple.Permissions); } } } if (relatedResources != null && relatedResources.Count > 0) { Table table = new Table(); table.Width = Unit.Percentage(100); foreach (File file in relatedResources) { //if control is security unaware OR if control is security aware and user is having //Read permission on the resource then only set the link. if (!IsSecurityAwareControl || (userPermissions.Keys.Contains(file.Id) && userPermissions[file.Id].Contains(UserResourcePermissions.Read))) { using (ResourceDataAccess dataAccess = new ResourceDataAccess(this.CreateContext())) { string fileSize = dataAccess.GetUploadedFileSize(file); if (!string.IsNullOrEmpty(fileSize)) { TableRow tr = new TableRow(); TableCell td = new TableCell(); td.HorizontalAlign = HorizontalAlign.Left; td.VerticalAlign = VerticalAlign.Top; td.Width = Unit.Percentage(70); LinkButton fileNameLink = new LinkButton(); fileNameLink.ID = file.Id.ToString(); fileNameLink.Text = HttpUtility.HtmlEncode(CoreHelper.FitString( CoreHelper.UpdateEmptyTitle(CoreHelper.GetFileName(file.Title, file.FileExtension)), _maxTitleCharWidth)); fileNameLink.Click += new EventHandler(fileNameLink_Click); td.Controls.Add(fileNameLink); tr.Cells.Add(td); td = new TableCell(); td.HorizontalAlign = HorizontalAlign.Left; td.VerticalAlign = VerticalAlign.Top; Label fileSizeLabel = new Label(); fileSizeLabel.Text = fileSize; td.Controls.Add(fileSizeLabel); tr.Cells.Add(td); table.Rows.Add(tr); } } } } BodyPanel.Controls.Add(table); success = true; } return(success); }