Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > How to display versioned image on page? View modes: 
User avatar
Member
Member
Blasty - 6/8/2010 4:24:21 PM
   
How to display versioned image on page?
Ok, so I'm using the workflow engine. I Use the DocumentHelper.GetDocument method and it returns my node.

in that node I have a column called Image that Has the GUID for the Image I was to display.

I do a node.GetValue("Image") and it gives me the GUID.

Then I set the ImageUrl property on my Asp:image object to equal

"~/CMSPages/GetFile.aspx?guid=" + imageGuid

This works on published documents, but no dice on a versioned document

So I've looked through API and other examples, and I stumble across a parameter
you can pass called "versionhistoryid"

Great, that's probably what it needs...but where do I get this elusive versionhistoryid

Someone suggested VersionManager.GetVersion in this Post, but either I'm reading it wrong or I have the wrong version because that method doesn't exist for me
Thread

So any help? I'm going to go work on a different area of my site, wasted entirely to much time on something I'm sure is supposed to be simple.

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 6/10/2010 5:21:53 AM
   
RE:How to display versioned image on page?
Hello,

You can get the attachment of the latest version. Is that right?

You use code like:

CMS.TreeEngine.TreeNode node = tree.SelectSingleNode(CMSContext.CurrentSiteName,

"/TestingWorkflow", CMSContext.CurrentUser.PreferredCultureCode, false, null, false);

if (node != null)

{

// Get the latest version of the document (always get the document with DocumentHelper

// when using workflow)

node = DocumentHelper.GetDocument(node, tree);

node.GetValue("Image")


Is that right?

What kind of image do you get? Is that the attachment of the last published version?

Thank you in advance for your reply.


Best regards,
Helena Grulichova

User avatar
Member
Member
Blasty - 6/10/2010 9:11:21 AM
   
RE:How to display versioned image on page?
My documents hasn't been published yet in this case, and it's in workflow.

I use code like this.

            CMS.TreeEngine.TreeProvider tree = new CMS.TreeEngine.TreeProvider(ui);

//get the cms_documents.documentId for this Pin

CMS.TreeEngine.TreeNode node = DocumentHelper.GetDocument(Convert.ToInt32(docId), tree);


//// Get document fields
if (node != null)
{
imgProposedImage.ImageUrl = "~/CMSPages/GetFile.aspx?guid=" node.GetValue("Image").ToString();
}


I checked the page and the correct GuiD is returned from workflow by DocumentHelper, it's giving me the GuiD that is for the item in workflow. The problem for me is that the GetFile.aspx doesn't show the image, even though the Guid is correct. So I'm assuming I need to provide versionhistoryID? If so, what's the correct code to get the versionhistoryId?

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 6/16/2010 8:17:27 PM
   
RE:How to display versioned image on page?
Hi,

if the attachment is within a document that is not published, the attachment won't be displayed in the live site. I'm assuming that's the main problem.
You can find implementation details in CMSPages\GetFile.aspx.cs, namely method:
protected void ProcessFile(Guid attachmentGuid, int versionHistoryId)

As for the VersionManager.GetVersion method you mentioned, it's probably:

VersionManager.GetDocumentHistory, which returns a DataSet according to the query "cms.versionhistory.selectdocumenthistory". There the VersionHistoryIDs should be present.
Some related methods or their overloads are described in the API reference available from Documentation page

You can also check some info on how to use controls for displaying attachments in article from DevGuide -
Handling attachments in transformations

Hope this helps.

Regards,
Zdenek