0

I need to access an ID to an adam file setup like this:

2sxc adam

MyDocument is the field name, where users can load an image or whatever. In a list style view, users will click a link that activates a detail view for that image.

The link will be something like mysite.com/mytab/detailsforfile/fileId

The details view will parse the fileId and load the image.

So, two questions:

  1. How can I access an ID for that adam file that later allows me to load that file based on that id?
  2. How can I access the URL of the file based on the ID created?

Is the native DNN file: 123 the only way? Or does 2sxc or adam have some specific ids?

Edit: A practical example would probably help:

This list view will have:

@foreach(var car in eCars) {
    <div>
         <strong>@car.Name</strong>
         <img class="img-fluid" src="@car.carImageOne">
         <a href="@("/whatever/" + IDFORTHISIMAGE)">See full image...</a>
         <img class="img-fluid" src="@car.carImageTwo">
         <a href="@("/whatever/" + IDFORTHISIMAGE)">See full image...</a>
    </div>
}

And the details view:

@{
    var qsImageId = Request.QueryString["whatever"];
    //cast and double check the qs int
    var imageURL = ??; // How do I get the file url based on the id?
}
<div>
    //embed nice frame, ads, whatever
    <img class="img-fluid" src="@imageURL">
</div>
João Gomes
  • 312
  • 2
  • 12

2 Answers2

1
  1. The IDs are normal IDs from Dnn/Oqtane
  2. To get the "raw" data use the Get method, and set convertLinks: false - see https://docs.2sxc.org/api/dot-net/ToSic.Sxc.Data.IDynamicEntity.html#ToSic_Sxc_Data_IDynamicEntity_Get_System_String_System_String_System_String_System_Boolean_System_Nullable_System_Boolean__
  3. To then get the file id back could be challenging. The 2sxc APIs aren't for public use and could change, so probably best to use DNN APIs to get it.

Alternative is to pass the entity-id to the details page, and there just get the entity and work with that - which is probably much easier.

iJungleBoy
  • 5,325
  • 1
  • 9
  • 21
  • Note that if you don't mind using more internal APIs you could also GetService – iJungleBoy Nov 22 '22 at 19:49
  • I can't use the entityID since there are several fields with adam files and I would need to send other info in the qs that I can't show. It needs to be a specific id for that image. I added a practical example on the original question for the list and details view. – João Gomes Nov 25 '22 at 22:22
0

To get the file ID I used this:

var getFile = AsAdam(Entity, "field").Files as System.Collections.Generic.IEnumerable<dynamic>;
get fileId = getFile.First().FileId;

To get the url from the id:

var myFile = FileManager.Instance.GetFile(FileId);
var myurl = FileManager.Instance.GetUrl(myFile);
João Gomes
  • 312
  • 2
  • 12