Not sure if you actually can get a unique url for older binarys. I would load the actual content item instead and use the stream from the binary object to show it...
Something like:
//The page you need versions for
ContentReference pageReference = new ContentReference();
//Load all versions
var repository = ServiceLocator.Current.GetInstance<IContentVersionRepository>();
var versions = repository.List(pageReference);
var contentRepository = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentRepository>();
foreach (var version in versions)
{
//Use contentRepository to grab the media files...
var media = contentRepository.Get<GenericMedia>(version.ContentLink);
var stream = media.BinaryData.OpenRead();
//use stream to render to user...
}
Thank you Daniel for you response. We ending up getting out the binary as you suggested. We actually implemented a webservice.
Example Url: {BaseUrl}/api/GetFile/1292_1506/filename.jpg
Code example:
[RoutePrefix("api")] public class LoadFileController : ApiController { private IContentRepository _contentRepository; private readonly BlobFactory _BlobFactory; public LoadFileController(IContentRepository contentRepository, BlobFactory blobFactory) { _contentRepository = contentRepository; _BlobFactory = blobFactory; } // <param name="fileName">Filename is only needed for the browser to know the filename. </param> [Route("GetFile/{imageCode}/{fileName}")] public HttpResponseMessage Get(string imageCode, string fileName) { try { var contentReference = new ContentReference(imageCode); var responseMessage = new HttpResponseMessage(HttpStatusCode.OK); var mediafile = _contentRepository.Get<MediaData>(contentReference) as MediaData; var blob = _blobFactory.GetBlob(mediafile.BinaryData.ID) Stream stream = blob.OpenRead() as Stream; responseMessage.Content = new StreamContent(stream); responseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue(mediafile.MimeType); responseMessage.Content.Headers.ContentLength = stream.Length; return responseMessage; } catch (Exception exception) { return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exception.Message); } } }
Sweet! ...and I do love web api :)
Btw...any reason you call .CreateWritableClone() ?
I don't see that you update it anywhere?
Then you save some memory and performance. EPiServer did a smart thing there building that model with readonly PageDatas as default to avoid creating a lot of unneccessary objects on heap which is quite expensive. :)
The customer needs to be able to upload new versions of a file and then be able to retrieve all file versions from viewmode.
I’m able to get version information by using "IContentVersionRepository” but I’m only able to load the latest binary.
My Question: How can I load the binary of older file versions?
My code:
Uploading new version
Retrieve versions: