Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > Getting the URL for a document in a user control (custom web part) View modes: 
User avatar
Member
Member
Darren-DesignReligion.co - 1/22/2010 6:09:14 AM
   
Getting the URL for a document in a user control (custom web part)
Hi all,

I am struggling to get a document URL with the API....

Let me try and explain what i am doing, see if it makes sense.

I have created a new document type - called Case Study.
This doc type has similar fields to the built in News type.
Using this new doc type i have created some documents in the site - all working.

I am creating a new web part which ultimately creates a list for use in a jQuery carousel. A single list item contains the CaseStudyTitle and also a thumbnail image CaseStudyThumbnail
This data is obtained using the CustomTableItemProvider class, and GetItems where my class of custom.CaseStudy is being used.
So far so good.

Now the problem i am having is getting the live URL to the CaseStudy document.

In the DataSet table i can only see columns for my custom table.

My question, is how can i use the data in the dataset to get a live URL for the document created using my CaseStudy doc type?

If this is not possible, what other way should i be creating my list?


I hope this make sense.......

To make things a little easier, here is the code so far:


CMS.TreeEngine.TreeProvider provider = new CMS.TreeEngine.TreeProvider();
CMS.SiteProvider.CustomTableItemProvider tp = new CMS.SiteProvider.CustomTableItemProvider(CMS.CMSHelper.CMSContext.CurrentUser);
DataSet ds = tp.GetItems("custom.CaseStudy", "", "");
string culture = CMS.CMSHelper.CMSContext.PreferredCultureCode;
string siteName = CMS.CMSHelper.CMSContext.CurrentSite.SiteName;


foreach (DataRow dr in ds.Tables[0].Rows){

// display title
string title = dr["CaseStudyTitle"].ToString();

// get Thumb image url
System.Guid thumbGUID = new Guid(dr["CaseStudyThumbnail"].ToString());
CMS.TreeEngine.TreeNode thumbNode = provider.SelectSingleNode(thumbGUID, culture, siteName);
string imageUrl = thumbNode.NodeAliasPath + ".aspx";

// get document url
//*********** THIS IS WHERE I AM STUCK AND NEED *************//


string docUrl = "#";
string link = "<a href='" + docUrl + "'><img src='" + imageUrl + "' /><br />" + title + "</a>";

// Output li element
HtmlGenericControl li = new HtmlGenericControl("li");
li.InnerHtml =link;
itemList.Controls.Add(li);
}




please help :-)


User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 1/22/2010 9:08:18 AM
   
RE:Getting the URL for a document in a user control (custom web part)
Hi,

could you please confirm me that I get your point?

You would like to know the live URL of document according the title? Is the title the document name?

Best regards,
Helena Grulichova

User avatar
Member
Member
Darren-DesignReligion.co - 1/22/2010 9:27:29 AM
   
RE:Getting the URL for a document in a user control (custom web part)
Hi Helena,

I have the Document name source field (under fields in document types) for a Case Study set to the CaseStudyTitle.

I can create the list of case studies in my control, though i can only get the information that is created under the fields tab in Document Types.

so, yes if the document name can lead me to the URL then that would be great. Also, would it still work if someone adjusted the title of a case study?

cheers

Darren

User avatar
Member
Member
Darren-DesignReligion.co - 1/26/2010 4:24:32 AM
   
RE:Getting the URL for a document in a user control (custom web part)
nudging... :-)

any ideas?

cheers

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 1/26/2010 5:57:20 AM
   
RE:Getting the URL for a document in a user control (custom web part)
Hello,

you could use the API method:

CMS.TreeEngine.DocumentURLProvider.GetUrl(aliasPath)

Best regards,
Helena Grulichova

User avatar
Member
Member
Darren-DesignReligion.co - 1/26/2010 6:06:33 AM
   
RE:Getting the URL for a document in a user control (custom web part)
hi Helena,

thanks for the response - though how to i get the aliasPath? - perhaps i am getting the wrong data in the first instance with the CustomTableItemProvider? as there is no aliasPath; only the properites i set in the document type.

regards
Darren

User avatar
Member
Member
Darren-DesignReligion.co - 1/26/2010 6:08:40 AM
   
RE:Getting the URL for a document in a user control (custom web part)
also, can't find DocumentURLProvider class in V4 .......

Regards
Darren

User avatar
Member
Member
Darren-DesignReligion.co - 1/26/2010 9:59:48 AM
   
RE:Getting the URL for a document in a user control (custom web part)

I figured it in the end.

For anybody else having a prob with this, i used the following:




CMS.TreeEngine.TreeProvider provider = new CMS.TreeEngine.TreeProvider();

string culture = CMS.CMSHelper.CMSContext.PreferredCultureCode;
string siteName = CMS.CMSHelper.CMSContext.CurrentSite.SiteName;
string className = "custom.CaseStudy";


DataSet nodes = provider.SelectNodes(siteName, "/%", culture, true, className);

foreach (DataRow dr in nodes.Tables[0].Rows)
{
// do your stuff in here
}