Retrieving file attachment url from CMS.File

mun yung kan asked on December 31, 2015 04:47

Hi Guys,

i'm trying to retrieve attachments from CMS.File node. specifically i've restricted users to uploading jpg and png.

i've been doing this to get the url:

string.Format("~/getattachment/{0}", node.GetStringValue("FileAttachment", ""));

which returns me a url like "../../getattachment/c86f6c3f-164a-487f-8926-b7fc3b5e210d"

how do i get the url of the attachment with the extension?

Recent Answers


Roman Hutnyk answered on December 31, 2015 15:33 (last edited on December 31, 2015 15:34)

You could try something like:

AttachmentInfo attachmentInfo = DocumentHelper.GetAttachment(documentGUID, tree, siteName, true);
                if (attachmentInfo != null)
                {
                    string fileExtension = attachmentInfo.AttachmentExtension;
                    filePath = VirtualPathUtility.ToAbsolute(AttachmentURLProvider.GetFilePhysicalURL(siteName, documentGUID, fileExtension));
                }
1 votesVote for this answer Mark as a Correct answer

mun yung kan answered on January 6, 2016 10:12

Hi Roman,

i'm able to get the attachmentInfo.

but the paths are resolving into a 404.

0 votesVote for this answer Mark as a Correct answer

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