简体   繁体   中英

2sxc - Access an adam file by unique identifier

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

2sxc亚当

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>
  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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM