3

I have an url (e.g. http://localhost/Aanbod/Pagina.aspx) and I want to know the tab id, so I can make a friendly url with query (e.g. http://localhost/Aanbod/Pagina/QueryKey/QueryValue/).

Anyone has an idea?

Edit:
I'm not on the page itself. Want to know it from any page possible.
The url does not contain the tab id itself, so it can't be extracted.

jerone
  • 16,206
  • 4
  • 39
  • 57

3 Answers3

8

if Pagina.aspx is a page in dotnet nuke like Home or Getting Started then you can find the tab id by

DotNetNuke.Entities.Tabs.TabController objTab = new DotNetNuke.Entities.Tabs.TabController(); 

DotNetNuke.Entities.Tabs.TabInfo objTabinfo = objTab.GetTabByName("Pagina", this.PortalId);

int Tabid = objTabinfo.TabID;
Salman Roy
  • 575
  • 2
  • 12
  • 27
  • 1
    This is also not the answer. You have to fill the page name, which is not the same as an url. First, we need to split the url into parents (could be done -> `GetTabByName("name", portalID, parentID)`), but then the page name is not the same as last part in the url. For example a page could be named `Child Page`, which DNN converts to the url `http://localhost/parent/childpage.aspx`. – jerone Jul 12 '13 at 13:10
1

Well, this post is a little bit old, and I don't know if someone still looks for a solution. I had this problem recently and here is the pieces of code I wrote to solve it:

public int GetTabIDFromUrl(string url, int portalID)
{
    int getTabIDFromUrl = 0;

    // Try the "old" way with the TabID query string
    if (url.ToLower().IndexOf("tabid") > 0)
    {
        Int32.TryParse(Regex.Match(url, "tabid[=/](\\d+)", RegexOptions.IgnoreCase).Groups[1].Value, out getTabIDFromUrl);
    }

    // When there is no result (because of advanced or human friendly or whatever Url provider)
    if (getTabIDFromUrl == 0)
    {
        TabCollection tabs = TabController.Instance.GetTabsByPortal(portalID);

        foreach (KeyValuePair<int, TabInfo> k in tabs)
        {
            TabInfo tab = k.Value;
            if (tab.FullUrl.StartsWith(url))
            {
                getTabIDFromUrl = tab.TabID;
                break;
            }
        }
    }
    return getTabIDFromUrl;
}

This could be a pain with sites that have a lot of pages, therefore it could be useful if you have some additional information to shrink the list that you have to loop through - e.g. a ModuleId of a module that is placed on this tab:

public int GetTabIDFromUrl(string url, int moduleID, int portalID)
{
    int getTabIDFromUrl = 0;

    // Try the "old" way with the TabID query string
    if (url.ToLower().IndexOf("tabid") > 0)
    {
        Int32.TryParse(Regex.Match(url, "tabid[=/](\\d+)", RegexOptions.IgnoreCase).Groups[1].Value, out getTabIDFromUrl);
    }

    // When there is no result (because of advanced or human friendly or whatever Url provider)
    if (getTabIDFromUrl == 0)
    {
        IList<ModuleInfo> modules = ModuleController.Instance.GetTabModulesByModule(moduleID);

        foreach (ModuleInfo module in modules)
        {
            TabInfo tab = TabController.Instance.GetTab(module.TabID, portalID);
            if (tab.FullUrl.StartsWith(url))
            {
                getTabIDFromUrl = tab.TabID;
                break;
            }
        }
    }
    return getTabIDFromUrl;
}

Hope that helps someone...

Happy DNNing! Michael

Michael Tobisch
  • 1,034
  • 6
  • 15
-1

I hope this will solve your issue

http://www.willstrohl.com/Blog/EntryId/66/HOW-TO-Get-DNN-TabInfo-page-object-from-TabId

Sorry, my bad!!

Here is your answer

http://www.dotnetnuke.com/Resources/Forums/forumid/118/threadid/89605/scope/posts.aspx :)

saadasharif
  • 80
  • 1
  • 14
  • This precisely the opposite. I don't know the tab id, I actually want to know it. – jerone Feb 29 '12 at 16:14
  • Again, this is not what I want. In the second link, the user has an url which contains the tabid and uses regular expressions to get the id. My url does not contain the tabid (as seen in the examples). – jerone Mar 01 '12 at 22:01
  • 1
    >. In the second link, the user has an url which contains the tabid and uses regular expressions to get the id. < This is bad practice anyway. You should never rely on the TabId being present in the Url, because it may change with any version of DotNetNuke, or the presence of an alternative Url scheme. – Bruce Chapman Oct 26 '12 at 03:23