Umbraco - Select node by URL - c#

I'm having issues with Umbraco when trying to get access to a node by it's url.
I've been trying to form an xpath query to select on the url, but I've no idea how to do that, and everything in their API is a 'dynamic' so I'm finding it impossible to dig much deeper for other methods.
The "Link to document" property in the Umbraco editor shows the path to be "/links/link-regions/link-region-1/". Its location in the editor is "/Data/Links/Link Regions/Link Region 1".
I suspect it'll look like this, but I cna't make it work:
//*[#url='/links/link-regions/link-region-1/']
I basically want to know what I have to do to get the node by providing either of these values and no others. I've been trying to do this for days now to no avail, please help!

If you're using Umbraco 4.11 or later, there are a new set of APIs that allow you to retrieve strongly-typed content (as opposed to dynamic - which can be frustrating when trying to evaluate types when debugging).
UmbracoContext.Current.ContentCache.GetByRoute(string url) should do what you want.

Related

Howto search within a Site with HTMLAgilityPack with changing search URLS

i am building a project to search for a specific driver at Lenovo Website (https://support.lenovo.com). This site changes the search URL while typing, if a suitable product category is found.
This means for example if you search for "ideapad" it uses:
http://pcsupport.lenovo.com/api_v2/de/de/Product/GetProducts?productId=ideapad
if you search for "T540p 20BE" the Url changes to:
http://pcsupport.lenovo.com/de/de/products/laptops-and-netbooks/thinkpad-t-series-laptops/thinkpad-t540p/20be?linkTrack=Homepage%3ABody_Search+Products&searchType=4&keyWordSearch=T540p%2520Laptop%2520%2528ThinkPad%2529%2520-%2520Type%252020BE
First i tried to use the url above http://pcsupport.lenovo.com/api_v2/de/de/Product/GetProducts?productId=[Searchpattern]. you get back a Json File which has further information to all modeltypes of that devices. Not the response i needed.
What i need is a way to get back all available drivers for some given Modell.
As Response to the search you get a Html Document, which contains all drivers in an embedded html page:
!]
I have tried different approches with selenium which works, but need a usabel way for my application. I tried with HTMLAgilityPack and xpath, but came not across the problem with changing search urls?
How can i get the Version and the Downloadlink ??
Update: Here is some example code. After not being able to get the correct syntax of the get Statemente, i tried to input the searchtext within the inputbox.
Goal: Be able to paste searchtext into the inputbox within the lenovo site, or overcome the changing urls (as mentioned above).
Extract the needed informations from the resulting driverpage
Edit: Just delete the unneeded code part. Can someone give me a hint for a working approach on this. If HtmlWeb is not the best solution, what would you prefer ?
You need to query for the corresponding elements and get the values you need. For example for version you need to query for the version DOM element (with tag, css class or any other attribute) and get the InnerText property. For the download links you need to query for the download element and get the href attribute.
If you have any problems during the development, add the code to the question to let us understand what you are doing and for what you are querying.
Edit: About the url search part. First of all, you need to understand that your HtmlDocument is not a browser and you cannot search products by filling the textbox in the site. You need to find other way to find the corresponding url for the inserted product. One option can be to get data from all available search urls, combine that data, and search inside of that combined one.

Can you Create a Keynote using the Revit API in C#

I'm trying to create a Keynote Tag via the Revit 2012 API. However, I found now reference to creating a Keynote Tag anywhere on the internet or in the samples. I see that the BuiltInCategory.OST_KeynoteTags is part of the IndependentTag class and according to http://thebuildingcoder.typepad.com/files/guide-to-placing-family-instances-with-the-api.doc you need to use the TM_ADDBY_CATEGORY TagMode to create a Keynote. However, when you then try to change the new Tag via ChangeTypeId, you get an error.
Has anyone figured this out?
I haven't had a chance to try yet, but I'm thinking you're out of luck.
For the most part, you can't do things with the API that you can't do interactively in Revit. I did quickly test that you can't change the type of a multi-category tag to be a keynote tag.
While they're both IndependentTag elements, they are different Categories, and it's very rare in my experience where you can switch the category of a placed element.

How to get a content node using Umbraco 5 API

I'm an Umbraco newbie and trying to get up to speed. One of the things i'm trying out is the API and accessing a node in the content tree. Unfortunately documentation is a bit thin and i can't find any info covering such a basic task...
I've got a simple content structure
Content > Home > About
How do i retrieve the About node using C# and the API from a plain old model class?
In other CMS's it would be as simple as calling Database.GetItem("/content/home/about")
How is this achieved with Umbraco v5?
Thanks
If you have a single, specific piece of content you want to get it, you can select it using the hiveid like so:
Umbraco.GetContentById("content://p__nhibernate/v__guid/0000000000000000")
You can find your content id by examining the content's properties from the backoffice.
EDIT:
If you truly must get the content by uri, you could do so by querying the hive. I can't recommend it for performance though.
_context.Application.Hive.QueryContent().Where(x => x.NiceUrl().Equals("/faq/functionality/submit-a-question",StringComparison.InvariantCultureIgnoreCase);

areanavigationsettings.aspx Programmatically

I've been messing with SPNavigationProvider, PublishingWebs, and etc for the past few days and I can not figure out how to move a node in /_layouts/areanavigationsettings.aspx programmatically.
The node I need to move is in the list of the Global Navigation, but when I query the SPPublihsingWeb.GlobalNavigationNodes it is not listed. When I call IncludeInNavigation() on the web I need in GlobalNavigationNodes, there is no change.
I'm doing this through a Feature Activation if that makes any difference.
I appreciate any help.
Thanks.
You probably want to do similar things I just did: Deploy custom Navigation / SiteMap via Feature?.
Instead of using the Publishing Site, why not use the SPWeb.Navigation?
Check out the following MSDN entry on Adding Links through Object Model - just iterate over the Children of SPWeb.Navigation and you will find your link and will be able to modify it.

Any way to associate a HtmlElement (.NET) to a JavaScript element?

I'm trying to make an extended version of a WebBrowser with stuff like highlighting text and getting properties or attributes of elements for a Web Scraper. WebBrowser functions doesn't help much at all, so if I could just find a way from HtmlElement to a JavaScript element (like the one returned by document.getElementById), and back, and then add JavaScript functions to the HTML from my application, it would make the job a lot easier. Right now I'm messing with the HTML of the code programmatically from C# and it's very messy. I was thinking about setting some unique Id to each HTML element from my program and then call the JavaScript document.getElementById to retrieve it. But that won't work, they might already have an Id assigned and I will mess up their HTML code. I don't know if I can give them some made up attribute like my_very_own_that_i_hope_no_web_page_on_the_world_ever_uses_attribute and then figure out if there is some JavaScript function getElementByWhateveAttributeIWant but I'm not sure if this would work. I read something about expansion or extended attributes on the DOM documentation in msdn but I'm not sure what that is about. Maybe some of you guys have a better way.
It would be much easier to use some rendering engine like trident to get the data from html document. Here is the Link for trident/MSHTML. you can do google and can have samples in c#
This is not nearly as hard as you imagine. You don't have to modify the document at all.
Once the WebBrowser has loaded a page, it's kept internally as a tree with the document node at the root. This node is available to your program, and you can find any element you want (or just enumerate them all) by walking the tree.
If you can give a concrete example, I can supply some code.

Categories