Developer forum

Forum » Templates » Linking to an item based page, that I only have the itemid on (don´t have the pageid)

Linking to an item based page, that I only have the itemid on (don´t have the pageid)

Hans Ravnsfjall
Hans Ravnsfjall
Reply

Hi

This is sort of related to this matter https://doc.dynamicweb.com/forum/development/development/how-to-get-value-from-paragraph-item-field

What I want to do, is to be able to link to an itembased page, that i only have the item id on. It is related to the matter above, but since the pageid is not a part of the Item. I have tried things like:

 

var siduid = item["PageId"];

But i can´t fetch the pageid because it is not pert of the item itself.

 

So my question is, is there any way of linking to a page I only know the itemid on?

Or is it possible to get the pageid when i know the itemid?

 

/Hans


Replies

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

????

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Hans

If you have the item type, you can do like this:

Services.Pages.GetPageForItem(string itemType,string itemId)

https://doc.dynamicweb.com/api/html/5a08068d-4274-eb81-d915-0b68ff879d4d.htm

BR Nicolai

Votes for this answer: 1
 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Thank you very mutch Nicolai, I will try that :)

/Hans

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Can´t quite get it to work.

Get an error saying:
"Line 745: An object reference is required for the non-static field, method, or property 'IPageService.GetPageForItem(string, string)'"

 

I have an item with the system name "Greinaskrivari", and the string @writeridstring contains the id of the Item I am trying to fetch the  page or pageid for.

My code looks like this

var writerpage=Dynamicweb.Content.IPageService.GetPageForItem("Greinaskrivari", @writeridstring);

 

What am I doing wrong?

 

/Hans

 

 

 
Nicolai Pedersen
Reply

Hi Hans

You need to call it like this: Dynamicweb.Services.Pages.GetPageForItem("Greinaskrivari", @writeridstring);

BR Nicolai

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Thank you very mutch for your time Nicolai. Getting closer, but when I output what i get from this - I get the following

"Dynamicweb.Content.Page"

I have also tried this, but this just gives an error

 

string   writerpagestring=writerpage["DwPageID"].ToString();

Sorry for my ignorance, but where do I go from here?

/Hans

 
Nicolai Pedersen
Reply

Something like this maybe?

int pageid = Dynamicweb.Services.Pages.GetPageForItem("Greinaskrivari", @writeridstring).ID;
<a href="Default.aspx?ID=@pageid">Link to page</a>
 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Brilliant Nicolai

Thank you, and a very good weekend to you :)

 

/Hans

 
Nicolai Pedersen
Reply

yes

 

You must be logged in to post in the forum