Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Cannot get attachment View modes: 
User avatar
Member
Member
ovidiu.lazar-evozon - 3/9/2011 10:20:21 AM
   
Cannot get attachment
Hi,
I'm having trouble getting an attachment that I used in a doctype.

What I have is a custom homepage, and in it, I can add any number of CarouselItems. I have a carousel item doctype.

This carousel item has several fields, among them an attachment which accepts an image to be uploaded.

I can get all fields values except for the attachment.

Here's my code. Please advise if possible.

Thanks in advance!


public partial class CMSTemplates_EntPartCanada_Homepage_Homepage : TemplatePage
{
protected void Page_Load(object sender, EventArgs e)
{
// current pate is the parent of all carousel items
var parent = CMSContext.CurrentDocument;

// node data source
var nodesDs = CMSContext.CurrentDocument.TreeProvider.SelectNodes(CMSContext.CurrentSiteName, parent.NodeAliasPath + "/%", null, true);
if (nodesDs == null || nodesDs.Tables == null || nodesDs.Tables.Count == 0) return;

// get carousel items
var table = nodesDs.Tables[0];
var carouselItems = new List<CarouselItem>();

// take each carousel item entry...
foreach (var carouselItemRow in table.Rows.Cast<DataRow>())
{
//... get the actual node
var carouselItemNodeId = (int)carouselItemRow["nodeid"];
var carouselItemNode = CMS.CMSHelper.CMSContext.CurrentDocument.TreeProvider.SelectSingleNode(carouselItemNodeId);

// then get all properties
carouselItems.Add(ProcessCarouselItem(carouselItemNode));
}
}

private CarouselItem ProcessCarouselItem(CMS.TreeEngine.TreeNode node)
{
if (node == null) return null;

var title = node.GetValue("title") as string;
var description = node.GetValue("description") as string;
var link = node.GetValue("link") as string;

var image = node.GetValue("image"); // returns empty string

// this doesn't work because the image node value is empty
Guid attachmentGuid = ValidationHelper.GetGuid(image, Guid.Empty);
string nodeAlias = ValidationHelper.GetString(node.GetValue("NodeAlias"), "");
string fileUrl = ResolveUrl(AttachmentManager.GetAttachmentUrl(attachmentGuid, nodeAlias));
// end code not working

return new CarouselItem()
{
Description = description,
Title = title,
Link = link,
Image = fileUrl
};
}
}

User avatar
Member
Member
ovidiu.lazar-evozon - 3/10/2011 6:07:02 AM
   
RE:Cannot get attachment
Never mind, I fixed it.
I was using the "document attachments" field type instead of "File".