Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Paul 55 posts 76 karma points
    Jan 02, 2012 @ 01:19
    Paul
    0

    Retrieving the currentNodeId using umbraco.NodeFactory.Node.getCurrentNodeId()

    Hello All,

    I am attempting to retrieve the current Node Id from .NET in order to get all the available domains but I am getting an error on the first line which retrieve the currentNodeId - Object Reference not set to an instance of an object. Any ideas of a remedy?

    Here is the code snippet

    int _currentNodeId = umbraco.NodeFactory.Node.getCurrentNodeId(); //Receiving an error here

    List<string> _cultureLists = new List<string>();
    Domain[] _domains = umbraco.library.GetCurrentDomains(_currentNodeId);

    foreach (Domain d in _domains) 
    {
    _culttureLists.Add(d.Language.CultureAlias);
    }

     

     

  • Rodion Novoselov 694 posts 859 karma points
    Jan 02, 2012 @ 01:47
    Rodion Novoselov
    0

    Hi. Could you tell in what context you make this api call? Because actually, the ID of the current node becomes available only after a certain stage of http request processing.

  • Paul 55 posts 76 karma points
    Jan 02, 2012 @ 02:01
    Paul
    0

    The call is made in a method called from the Page_Load Event in .NET

    protected void Page_Load(object sender, EventArgs e)
    {
    if (!Page.IsPostBack)
    {
    ...
    string = getCurrentCulture();
    ...
    } else if (Page.IsPostBack) {
    ...
    }
    }

    private string getCurrentCulture() 

    int _currentNodeId = umbraco.NodeFactory.Node.getCurrentNodeId(); //Receiving an error here

     

    List<string> _cultureLists = new List<string>();
    Domain[] _domains = umbraco.library.GetCurrentDomains(_currentNodeId);

    foreach (Domain d in _domains) 
    {
    _culttureLists.Add(d.Language.CultureAlias);
    }
    ...

  • Paul 55 posts 76 karma points
    Jan 02, 2012 @ 02:10
    Paul
    0

    I still get the error if I place the call in the Page_Init(object sender, EventArgs e) {} Event.

    If I place the call in the Page_PreInit(object sender, EventArgs e)  {} Event. The usercontrol runs but it does not return any data.

    I am attempting to create a custom DataType for use in umbraco.

  • Rodion Novoselov 694 posts 859 karma points
    Jan 02, 2012 @ 02:20
    Rodion Novoselov
    0

    Ok, and where is this Page_Load method? Is it some regular aspx page (like the ones inside ~/umbraco)?

  • Paul 55 posts 76 karma points
    Jan 02, 2012 @ 02:33
    Paul
    0

    Yes this is in a usercontrol which has been compiled and placed in the usercontrols subfolder in umbraco.

    Testing it from Visual Studio and running it from umbraco after adding it as a Data type and selecting umbraco user control wrapper option for the Render control gives this error.

  • Paul 55 posts 76 karma points
    Jan 02, 2012 @ 02:37
    Paul
    0

    Depending on the current culture, I will present a list of culture sensitive options within a drop down list box to the end user.

  • Rodion Novoselov 694 posts 859 karma points
    Jan 02, 2012 @ 03:37
    Rodion Novoselov
    0

    Paul, it seems to me that the curent node id would not be accessible this way from within a data type control (like a user control wrapper). But probably the solution could be getting it from the query string (Request.QueryString["id"]) since the document editor actually is an iframe where the query string include the id of a node being currently edited (like editContent.aspx?id=xxx).

  • Paul 55 posts 76 karma points
    Jan 02, 2012 @ 03:53
    Paul
    0

    That will make defining a datatype difficult if one has to be culture aware, since the datatype must be defined in umbraco at the backend and not at the web site.

  • Paul 55 posts 76 karma points
    Jan 02, 2012 @ 04:03
    Paul
    0

    I attempted to use the umbracoUrlName property where I define the url for the page as - myPage?id=culture, since we may not specify the .aspx extension using the umbracoUrlName property. After saving, the link changes to myPageid=culture.aspx, so this will not work.

  • Paul 55 posts 76 karma points
    Jan 02, 2012 @ 06:45
    Paul
    0

    This looking for other suggestions on this. I used the following snippet which compiles and I'm able to generate a Custom DataType:

              List<Language> _cultureLists = Language.GetAllAsList().ToList<Language>();

    but the data presented within the DropDownListBox is not culture aware.

    How do I find the current language setting of umbraco?

  • Rodion Novoselov 694 posts 859 karma points
    Jan 02, 2012 @ 11:04
    Rodion Novoselov
    0

    Hi again. Paul, am I right that you just want to get something like a current locale? Then I could suggest that you could just get the domain part of a current request URL, then get the Domain with Domain.GetDomain(domainName) and then get the Domain.Language property of the result. Does that resolve your issue?

  • Paul 55 posts 76 karma points
    Jan 02, 2012 @ 11:13
    Paul
    0

    How do you determine the domainName string to pass?

    If this were a usercontrol that was used to populate a page, I'll gladly set a DictionaryItem with the domainName or cultureAlias. But this is being used to configure a custom DataType's where the Render Control is set to a umbraco user control wapper.

  • Rodion Novoselov 694 posts 859 karma points
    Jan 02, 2012 @ 12:20
    Rodion Novoselov
    0

    For example you can try this way:

    var domainName = Request.ServerVariables["HOST_NAME"];
    var domain = Domain.GetDomain(domainName);
    if(domain != null) {
    var culture = domain.Language.CultureAlias;
  • Paul 55 posts 76 karma points
    Jan 02, 2012 @ 18:10
    Paul
    0

    We are very close. The HOST_NAME is not one of the accepted server variables.

  • Rodion Novoselov 694 posts 859 karma points
    Jan 02, 2012 @ 18:37
    Rodion Novoselov
    0

    Oh. I made a tipo. Sure I meant "HTTP_HOST" instead of "HOST_NAME" :-) 

  • Paul 55 posts 76 karma points
    Jan 02, 2012 @ 20:32
    Paul
    0

    Great. It work! Thanks a lot for your assistance.

Please Sign in or register to post replies

Write your reply to:

Draft