|
1 | 1 | ---
|
2 | 2 | title: "Use file column data (Microsoft Dataverse) | Microsoft Docs" # Intent and product brand in a unique string of 43-59 chars including spaces
|
3 | 3 | description: "Learn about uploading, downloading, and deleting data in file columns." # 115-145 characters including spaces. This abstract displays in the search result.
|
4 |
| -ms.date: 11/02/2022 |
| 4 | +ms.date: 11/08/2022 |
5 | 5 | ms.reviewer: jdaly
|
6 | 6 | ms.topic: article
|
7 | 7 | author: NHelgren # GitHub ID
|
@@ -30,6 +30,12 @@ Each file column has a supporting read-only string column that contains the name
|
30 | 30 | > [!NOTE]
|
31 | 31 | > The file name column does not appear in the [Power Apps](https://make.powerapps.com/?utm_source=padocs&utm_medium=linkinadoc&utm_campaign=referralsfromdoc) designer.
|
32 | 32 |
|
| 33 | +## Relationship to FileAttachment table |
| 34 | + |
| 35 | +When a file column is created for a table, a new one-to-many relationship is created between the table and the `FileAttachment` table. The name of the relationship is `{table logical name}_FileAttachments`. For example, if the file column is part of the account table, the relationship name will be `account_FileAttachments`. |
| 36 | + |
| 37 | +You can use this relationship to return additional data about the file column and any other file columns for the table. More information: [Retrieve additional information about files for a record](#retrieve-additional-information-about-files-for-a-record). |
| 38 | + |
33 | 39 | ## Behavior when retrieving
|
34 | 40 |
|
35 | 41 | When you retrieve a record and include a file column, the value returned will be a unique identifier for the file. You can use this value to delete the file using the `DeleteFile` message. There is no other use for this id other than to check whether the column has a value. More information: [Use the DeleteFile message](#use-the-deletefile-message).
|
@@ -101,6 +107,121 @@ More information: [Retrieve a table row using the Web API](webapi/retrieve-entit
|
101 | 107 |
|
102 | 108 | ---
|
103 | 109 |
|
| 110 | +### Retrieve additional information about files for a record |
| 111 | + |
| 112 | +You can use the relationship between the file column table and the `FileAttachment` table to return information about all file columns associated to that table row. |
| 113 | + |
| 114 | +#### [SDK for .NET](#tab/sdk) |
| 115 | + |
| 116 | +The `RetrieveAccountRecordWithFileData` static method below will return information about all the file columns that contain data related to the `account` record with the matching `accountid` value. |
| 117 | + |
| 118 | +```csharp |
| 119 | +static void RetrieveAccountRecordWithFileData(IOrganizationService service, Guid accountid) |
| 120 | +{ |
| 121 | + // Create query for related records |
| 122 | + var relationshipQueryCollection = new RelationshipQueryCollection { |
| 123 | + { |
| 124 | + new Relationship("account_FileAttachments"), |
| 125 | + new QueryExpression("fileattachment"){ |
| 126 | + ColumnSet = new ColumnSet( |
| 127 | + "createdon", |
| 128 | + "mimetype", |
| 129 | + "filesizeinbytes", |
| 130 | + "filename", |
| 131 | + "regardingfieldname", |
| 132 | + "fileattachmentid") |
| 133 | + } |
| 134 | + } |
| 135 | + }; |
| 136 | + |
| 137 | + // Include the related query with the Retrieve Request |
| 138 | + RetrieveRequest request = new RetrieveRequest |
| 139 | + { |
| 140 | + ColumnSet = new ColumnSet("accountid"), |
| 141 | + RelatedEntitiesQuery = relationshipQueryCollection, |
| 142 | + Target = new EntityReference("account", accountid) |
| 143 | + }; |
| 144 | + |
| 145 | + // Send the request |
| 146 | + RetrieveResponse response = (RetrieveResponse)service.Execute(request); |
| 147 | + |
| 148 | + //Display related FileAttachment data for the account record |
| 149 | + response.Entity.RelatedEntities[new Relationship("account_FileAttachments")] |
| 150 | + .Entities.ToList().ForEach(e => |
| 151 | + { |
| 152 | + Console.WriteLine($"createdon: {e.FormattedValues["createdon"]}"); |
| 153 | + Console.WriteLine($"mimetype: {e["mimetype"]}"); |
| 154 | + Console.WriteLine($"filesizeinbytes: {e.FormattedValues["filesizeinbytes"]}"); |
| 155 | + Console.WriteLine($"filename: {e["filename"]}"); |
| 156 | + Console.WriteLine($"regardingfieldname: {e["regardingfieldname"]}"); |
| 157 | + Console.WriteLine($"fileattachmentid: {e["fileattachmentid"]}"); |
| 158 | + }); |
| 159 | +} |
| 160 | +``` |
| 161 | + |
| 162 | +**Output**: |
| 163 | + |
| 164 | +In this case, there is a single file column in the account table named `sample_filecolumn`, and this is the data about the file stored in that column. |
| 165 | + |
| 166 | +``` |
| 167 | +createdon: 10/22/2022 2:01 PM |
| 168 | +mimetype: application/pdf |
| 169 | +filesizeinbytes: 25,870,370 |
| 170 | +filename: 25mb.pdf |
| 171 | +regardingfieldname: sample_filecolumn |
| 172 | +fileattachmentid: 63a6afb7-4c52-ed11-bba1-000d3a9933c9 |
| 173 | +``` |
| 174 | + |
| 175 | +More information: |
| 176 | + |
| 177 | +- [What is the Organization service](org-service/overview.md) |
| 178 | +- [Retrieve with related rows](org-service/entity-operations-retrieve.md#retrieve-with-related-rows) |
| 179 | + |
| 180 | +#### [Web API](#tab/webapi) |
| 181 | + |
| 182 | +The request below below will return information about all the file columns that contain data related to the `account` record with `accountid` equal to `352edda9-4c52-ed11-bba1-000d3a9933c9`. |
| 183 | + |
| 184 | +**Request** |
| 185 | + |
| 186 | +```http |
| 187 | +GET [Organization URI]/api/data/v9.2/accounts(352edda9-4c52-ed11-bba1-000d3a9933c9)?$filter=sample_filecolumn%20ne%20null&$expand=account_FileAttachments($select=createdon,mimetype,filesizeinbytes,filename,regardingfieldname)&$select=accountid HTTP/1.1 |
| 188 | +OData-MaxVersion: 4.0 |
| 189 | +OData-Version: 4.0 |
| 190 | +If-None-Match: null |
| 191 | +Accept: application/json |
| 192 | +``` |
| 193 | + |
| 194 | +**Response** |
| 195 | + |
| 196 | +In this case, there is a single file column in the account table named `sample_filecolumn`, and this is the data about the file stored in that column. |
| 197 | + |
| 198 | +```http |
| 199 | +HTTP/1.1 200 OK |
| 200 | +Content-Type: application/json; odata.metadata=minimal |
| 201 | +OData-Version: 4.0 |
| 202 | +
|
| 203 | +{ |
| 204 | + "@odata.context": "[Organization URI]/api/data/v9.2/$metadata#accounts(accountid,account_FileAttachments(createdon,mimetype,filesizeinbytes,filename,regardingfieldname))/$entity", |
| 205 | + "@odata.etag": "W/\"75119522\"", |
| 206 | + "accountid": "352edda9-4c52-ed11-bba1-000d3a9933c9", |
| 207 | + "account_FileAttachments": [ |
| 208 | + { |
| 209 | + "@odata.etag": "W/\"75119363\"", |
| 210 | + "createdon": "2022-10-22T21:01:45Z", |
| 211 | + "mimetype": "application/pdf", |
| 212 | + "filesizeinbytes": 25870370, |
| 213 | + "filename": "25mb.pdf", |
| 214 | + "regardingfieldname": "sample_filecolumn", |
| 215 | + "fileattachmentid": "63a6afb7-4c52-ed11-bba1-000d3a9933c9" |
| 216 | + } |
| 217 | + ] |
| 218 | +} |
| 219 | +``` |
| 220 | + |
| 221 | +More information: [Retrieve with related rows](org-service/entity-operations-retrieve.md#retrieve-with-related-rows) |
| 222 | + |
| 223 | +--- |
| 224 | + |
104 | 225 | ## Upload Files
|
105 | 226 |
|
106 | 227 | There at three different ways to upload files to a file column:
|
|
0 commit comments