API Questions on Kentico API.
Version 6.x > API > Reading CMS.File info View modes: 
User avatar
Member
Member
Regus - 10/9/2012 8:22:04 AM
   
Reading CMS.File info
So, I created my own webpart wich reads some cms.file documents. The documents I'm trying to read are images. So I need to get the imageurl of this file, but I can't see how. I 'can't find a property which retreives the complete filepath of the image.

Here's my code.


DataSet documents = tree.SelectNodes(CMSContext.CurrentSiteName, "/%", "en-US", false, "CMS.File");

if (documents != null && !DataHelper.DataSourceIsEmpty(documents))
{
foreach (DataRow documentRow in documents.Tables[0].Rows)
{
TreeNode node = TreeNode.New(documentRow, "CMS.File", tree);
string filename = node.GetValue("FileName").ToString();
string fullpath = ????
}
}

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 10/10/2012 6:23:04 AM
   
RE:Reading CMS.File info
Hi,

from the table you could also get the GUID of the image. After that you could retrieve the URL path by GUID using the piece of code like this:
                //input
string nodeGuidStr = <GUID in the string format>;

//output
string url = "";

Guid nodeGUID = new Guid(nodeGuidStr);

if (nodeGUID != null)
{
int nodeId = CMS.TreeEngine.TreePathUtils.GetNodeIdByNodeGUID(nodeGUID, CMS.CMSHelper.CMSContext.CurrentSiteName);

if (nodeId != null)
{
CMS.TreeEngine.TreeProvider tp = new CMS.TreeEngine.TreeProvider(CMS.CMSHelper.CMSContext.CurrentUser);

CMS.TreeEngine.TreeNode node = tp.SelectSingleNode(nodeId);

url = AttachmentManager.GetPermanentDocUrl(nodeGUID, node.NodeAlias, CMSContext.CurrentSiteName);
}
}
So with the GUID you are able to retrieve the full path of the file.

Best regards,
Martin Danko

User avatar
Member
Member
Regus - 10/10/2012 8:02:23 AM
   
RE:Reading CMS.File info
Thanks Martin !