How to set src to image if the particular field type is file in custom web part if the html is build

Srinivasa Rao Potnuru asked on June 21, 2017 15:53

Hi,

We have a requirement to build the html dynamically using string builder in custom web part i.e. CMSAbstractWebPart. We need to set src to image, the value is from page type field File.

we can set the image url to image in transformation like below but how can we set image url to image in custom web part code.

In Transfromation: <img alt='<%# Eval("Title") %>' src='<%# GetFileUrl("ThumbnailImage") %>'/>

Do we have to convert the AttachmentBinary from "CMS_Attachment" where AttachmentGUID=@attachmentguid to image bytes? or is there any other way.

Please help.

Thanks & Regards, Srinivas

Recent Answers


Roman Hutnyk answered on June 21, 2017 17:21 (last edited on June 21, 2017 17:26)

Try something like:

/getattachment/[attachmentGuid].aspx

Attachment Guid should be stored into your file field.

0 votesVote for this answer Mark as a Correct answer

Srinivasa Rao Potnuru answered on June 22, 2017 16:20 (last edited on June 22, 2017 16:21)

Tried with with below but not working..Image is not rendering src='/getattachment/" + drArticle["ThumbnailImage"].ToString() + ".aspx'

0 votesVote for this answer Mark as a Correct answer

Srinivasa Rao Potnuru answered on June 22, 2017 16:28

"<a href='/getattachment/" + attachment.AttachmentGUID + "/attachment.aspx'>" ==> IS WORKING FINE

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.