Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / How to display image i...
Finance forum
Answered

How to display image in SSRS from attachments?

Posted on by 35

Hi everybody,

I need to retrieve preview image in Attachment, but I don't know how.

42404082.png

I try to using DocuRef, DocuValue, ImageReference and DocumentManagement but all failed.

DocuRef docuRef;

select firstonly docuRef
    where docuRef.RefRecId  ==  hcmWorker.RecId;

DocuValue   docuValue;
        
select firstonly docuValue
    where docuValue.RecId == docuRef.ValueRecId;

ImageReference imageReference = DocumentManagement::getThumbnail(docuRef);
              
demoTmp.ImageStr = DocumentManagement::construct().getDisplayUrl(docuRef);
//container conImgRef = ImageReference::GetPackedBinaryData(docuValue.AccessInformation);

//demoTmp.Image   =  ImageReference::GetPackedBinaryData(imageReference.parmImageData()); //DocumentManagement::getThumbnailAsContainer(docuRef);
demoTmp.ImageStr = DocumentManagement::construct().getImageFrameUrl(docuRef); //DocumentManagement::construct().getPreviewUrl(docuRef);
demoTmp.ImageStr = DocumentManagement::construct().getPreviewUrl(docuRef);        
demoTmp.ImageStr = DocumentManagement::construct().getDisplayUrl(docuRef);

demoTmp.ImageStr = docuRef.originalFileName();

I got the result is 127.0.0.1:10000/devstoreaccount1/documents/CD15AC4E-xxxx-xxxx-xxxx-DB4B81xxxxxx and filemanagement/_t/cd15ac4e-xxxx-xxxx-xxxx-db4b81xxxxxx?access_token=eyJDb21wYW55IjoiVEhNRiIsIkhhc2xxxxxRva2VuIjoiODNWWlVDSzY5Q0wwZ0JwazA1OFM0TWpKdmpOVxxxxxNkS1M1R2ZRU3FyclJRXC92anNVYUs0WHAyNlpMc1xxxxA0Z1ZienpWSmg4XC9TcXQ2MVE2UxxxxxUGFydGl0aW9uIjo1NjM3MTQ0NTc2LCJxxxxxSWQiOjU2MzcxNDQ1NzYsIlZhbGlkVW50aWxxxxxcL0RhdGUoMTY0MTI2NzQ4MxxxxxcLyIsIkZpbGVJZCI6ImNkMTVhYzRlLTM1YzktNDIzNC05MmEwLWRiNGI4MxxxxxTUyOCJ9&ms-dyn-caid=95cxxxxx-xxxx-0000-3b8c-c09511xxxxxx

I don't know how to present in container for display image in SSRS.

I spend a lot of time, I can't do that. Please help or give any suggestion to me.

Thank you so much.

  • Suggested answer
    CU07071551-1 Profile Picture
    CU07071551-1 120 on at
    How to display image in SSRS from attachments?
    IMFA, Loan, Customer Care Number//9748798367))) Toll 97487983_67})}}}}-Free.All Releted+call-
  • Suggested answer
    CU07071551-1 Profile Picture
    CU07071551-1 120 on at
    How to display image in SSRS from attachments?
    IMFA, Loan, Customer Care Number//9748798367))) Toll 97487983_67})}}}}-Free.All Releted+call-
  • PST Profile Picture
    PST 35 on at
    RE: How to display image in SSRS from attachments?

    Oh, Thank you Martin.

    This code work fine:

    demoTmp.Image = DocumentManagement::getAttachmentAsContainer(docuRef);

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 228,501 Most Valuable Professional on at
    RE: How to display image in SSRS from attachments?

    You're making it more complicated than needed. Rather then fixing problems with your solution, let's me show you an easier way.

    Let me replace your code:

    str ss = strFmt("usnconeboxax1aos.cloud.onebox.dynamics.com/%1", DocumentManagement::getAttachmentPublicUrl(docuRef));
    System.IO.Stream stream = File::UseFileFromURL(ss);
    Binary binary = Binary::constructFromMemoryStream(stream);
    Bitmap bitmap = binary.getContainer();
    demoTmp.Image = bitmap;

    with this:

    demoTmp.Image = DocumentManagement::getAttachmentAsContainer(docuRef);

    Not only that it easier to write and it has less space for mistakes, but it's also not specific to a single kind of file storage.

    By the way, notice that my code snippets are easier to read, because then don't contain double line spacing. It's not seen here, but these code blocks also preserve line indentation. Line numbers are often useful too. When pasting code, please use Insert > Code (in th rich formatting view) instead of just pasting code as normal text.

  • PST Profile Picture
    PST 35 on at
    RE: How to display image in SSRS from attachments?

    Hi Alex,

    Thank you so much for your reply.

    I try to test by DocumentManagement::getAttachmentPublicUrl(docuRef).

    Result don't any error but still cannot display image in SSRS (Image MIME type is bmp).

    (Full code below:

    str ss = strFmt("usnconeboxax1aos.cloud.onebox.dynamics.com/%1", DocumentManagement::getAttachmentPublicUrl(docuRef));

    System.IO.Stream        stream = File::UseFileFromURL(ss);

    Binary binary = binary::constructFromMemoryStream(stream);

    Bitmap bitmap = binary.getContainer();

    demoTmp.Image   =   bitmap;

    )

    I try to test by DocumentManagement::getAttachmentStream(docuRef).

    Result error in line: Binary binary = binary::constructFromMemoryStream(stream);

    Error: System.ArgumentException: 'Invalid argument type; System.IO.MemoryStream is required. Parameter name: memoryStream'

    (Full code below:

    System.IO.Stream        stream = DocumentManagement::getAttachmentStream(docuRef);

    Binary binary = binary::constructFromMemoryStream(stream);

    Bitmap bitmap = binary.getContainer();

    demoTmp.Image   =   bitmap;

    )

    I try to access link: https://usnconeboxax1aos.cloud.onebox.dynamics.com/filemanagement/cd15ac4e-xxxx-xxxx-xxxx-db4b81xxxxxx?access_token=eyJDb21wYW5xxxxxiIsIkhhc2hlZFRva2VxuIjoxxxxxxxiYU9DOWpRM29jbXBcL2ZRMUxxxxxxDSkxWOHI4TlkxWERIUlVpN2VDZVwvYVwvYzBKUmMwx4SmE0UE01MxxxxEdHWkcxbkcwexxxxxE9PSIsIlBhcnRpdGlvxxxxxNxU3xxxNlcklkIjo1NjM3MTQxxxx0xYWxpZFVudGlsIjxxxx2NDMwOxxxDgwNTYpXC8ixiOiJjZDxS0zNxxxxMxxxxxxxtOTJhMxxxxxxODE2Mjk1MjgifQ%3D%3D&ms-dyn-caid=xxxx-11a7-xxx-27xx-4001xxxxxx on web browser, the system can download the pictures I attached.

    but I'm not sure if I'm displaying it correctly on SSRS.

    I think it's close to being able to get it.

    Do you have any idea?

  • Alex VN Profile Picture
    Alex VN 1,987 on at
    RE: How to display image in SSRS from attachments?

    Hi,

    I think because the attachment is uploaded to a protected blob and the url you used is an internal link.

    You can try to use:

    DocumentManagement::getAttachmentPublicUrl(docuRef1). This will return a public url:

    filemanagement/_t/cd15ac4e-xxxx-xxxx-xxxx-db4b81xxxxxx?access_token=eyJDb21wY

    With this you need to append your environment url like below to get an public access link:

    abcdev.cloudax.dynamics.com/filemanagement/_t/cd15ac4e-xxxx-xxxx-xxxx-db4b81xxxxxx?access_token=eyJDb21wY

    Another way you can try is to use:

    DocumentManagement::getAttachmentStream(docuRef1). This will provide you with the stream object. I tested with my Cloudhosted environment and it is working as expected.

    Hope this will help.

  • PST Profile Picture
    PST 35 on at
    RE: How to display image in SSRS from attachments?

    Hi Alex

    Thank you for your response.

    My DB is original DB on Sandbox.

    I change image and upload a new file then error has still the same.

    Do you have any idea?

  • Suggested answer
    Alex VN Profile Picture
    Alex VN 1,987 on at
    RE: How to display image in SSRS from attachments?

    Hi,

    I think your DB might be a restored one so the attachment is actually not there in the system so that's why you got the error. I would recommend you to test with a new file uploaded and can be previewed in the system or if can you can test it with your sandbox environment.

    Regards,

  • PST Profile Picture
    PST 35 on at
    RE: How to display image in SSRS from attachments?

    Hi Alex,

    I test on my VM (Created from VHD of Microsoft).

    I try to connect to 127.0.0.1:10000/devstoreaccount1/documents/CD15AC4E-xxxx-xxxx-xxxx-DB4B81xxxxxx on web browser, I found the error is "This XML file does not appear to have any style information associated with it. The document tree is shown below.", error message is "ResourceNotFound - The specified resource does not exist."

    I try to test with public URL image link, I can get the image on my SSRS.

    Do you have any idea?

  • Alex VN Profile Picture
    Alex VN 1,987 on at
    RE: How to display image in SSRS from attachments?

    Hi,

    I think you are testing on a cloud hosted environment and the url seems to be a local one. Can you try to check if you access this url you can 127.0.0.1:10000/devstoreaccount1/documents/CD15AC4E-xxxx-xxxx-xxxx-DB4B81xxxxxx  download the filed?

    From Sandbox for attachment I think you will get a  blob URL instead so I think you can try to test with a public image URL hardcoded and check further.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,532 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,501 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans