How to access the current document/node in an umbraco backend user control/data type Options
chimnit
Posted: Wednesday, February 06, 2008 10:58:26 AM
Rank: Devotee

Joined: 10/25/2007
Posts: 59
Hi everybody

I'm struggeling creating a new data type/user control for the umbraco backend. I'm struggeling because I cannot find a way to get the current document (the one the usercontrol is located in). I need to get the ID of the document. I have tried the following in the PageLoad() method of the user control:

Code:
umbraco.presentation.nodeFactory.Node currentNode = umbraco.presentation.nodeFactory.Node.GetCurrent();


But that throws an exception:

Code:
[NullReferenceException: Object reference not set to an instance of an object.]
   umbraco.presentation.nodeFactory.Node.GetCurrent() +64
   umbracoControls.FlashBanner.Page_Load(Object sender, EventArgs e) +165
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
   System.Web.UI.Control.OnLoad(EventArgs e) +99


Does anybody know if there is another API method I should use????

Thanks in advance :o)

Kim
chimnit
Posted: Wednesday, February 06, 2008 11:00:01 AM
Rank: Devotee

Joined: 10/25/2007
Posts: 59
Hi again,

Something got lost in the post. I have tried to use the following in the PageLoad method of the user control:

Code:
umbraco.presentation.nodeFactory.Node currentNode = umbraco.presentation.nodeFactory.Node.GetCurrent();
tim
Posted: Wednesday, February 06, 2008 11:11:34 AM

Rank: Addict

Joined: 2/19/2007
Posts: 671
Location: Belgium
Hi Kim,

If it is for a usercontrol that is used in the backend you can get the id by:

Request["id"]


Cheers,
Tim

Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
chimnit
Posted: Wednesday, February 06, 2008 12:28:57 PM
Rank: Devotee

Joined: 10/25/2007
Posts: 59
Hi Tim

Thanks for the info. That did the trick :o)

But is there an API method for retrieving the document and latest version based on the document ID???

Thanks in advance :o)

Cheers,

Kim
tim
Posted: Wednesday, February 06, 2008 12:34:12 PM

Rank: Addict

Joined: 2/19/2007
Posts: 671
Location: Belgium
Sure there is, but I don't think it is recommended to use when you are making a new datatype.

Code:


using umbraco.cms.businesslogic.web;
using umbraco.cms.businesslogic.property;


Document movie = new Document(Convert.ToInt32(docid));

                    if (isUnique(movie, txtEmail.Text))
                    {
                        //create new vote
                        DocumentType voteDocTyp = DocumentType.GetByAlias("Vote");

                        Document vote = Document.MakeNew(txtEmail.Text, voteDocTyp, new umbraco.BusinessLogic.User(0), movie.Id);

                        vote.getProperty("emailaddress").Value = txtEmail.Text;
                        vote.getProperty("subscribe").Value = cbPromotions.Checked;

                        vote.Publish(new umbraco.BusinessLogic.User(0));
                        umbraco.content.Instance.RefreshContentFromDatabaseAsync();
                    }


Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
chimnit
Posted: Wednesday, February 06, 2008 1:25:33 PM
Rank: Devotee

Joined: 10/25/2007
Posts: 59
OK... Do you have alternative suggestions for accessing the current documents preview address???

E.g.

Code:
http://domain.dk/1041.aspx?umbVersion=4250f4d2-0c4d-44a5-987d-8049420784c3


Once again thanks for the input. It has been very helpful already :o)

/Kim
tim
Posted: Wednesday, February 06, 2008 1:54:08 PM

Rank: Addict

Joined: 2/19/2007
Posts: 671
Location: Belgium
Not really, try looking at the umbraco source code and finding out what code is behind the preview button

Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
chimnit
Posted: Wednesday, February 06, 2008 1:59:39 PM
Rank: Devotee

Joined: 10/25/2007
Posts: 59
I'll try to have a look at it... Thanks a lot for your help so far :o)

Kim
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.