I have a simple Examine search like so;
var results = Umbraco.Search(Request.QueryString["query"], true, "MySearcher");
foreach (var result in results)
{
<h2>#result.Name</h2>
<p>Content from 'contentgrid'?</p>
}
My question is, how do I get a snippet of text from the Grid? Propertyname is contentgrid.
Viewing the index, I can see there is a property named contentgrid containing the text, stripped from formatting etc.
Hi I wrote some code to allow you to do a more advanced search in umbraco.
This article gives you that code.
http://www.codeshare.co.uk/blog/how-to-search-by-document-type-and-property-in-umbraco/
I use it for the search on my website. The word mismatched only appears in the content grid for one article of my site. The below search url proves that it works.
http://www.codeshare.co.uk/search/?query=mismatched
Kind regards
Paul
I think there are two approaches you could take.
One is to add a custom field in the Examine index and then using the GatheringNodeData event, index the text that you want to display. That way you will be able to access it from the SearchResult object (#result.Fields["customFieldName"]). The GatheringNodeData event handler will have to parse the grid data to extract the text snippet you want and then add it to the Examine document (e.Fields["content"] = textSnippet).
The other approach would be to get the text snippet from the node when displaying the results.
var helper = new UmbracoHelper(UmbracoContext.Current);
foreach (var result in results)
{
var node = helper.TypedContent(result.Id);
var gridData = node.GetPropertyValue("contentgrid");
// some code for extracting the text snippet from the grid data
}
Note in both techniques, you need to figure out how to extract the text snippet you want from the grid data. You could use Skybrud.Umbraco.GridData or just parse the JSON yourself (using JSON.NET). I think the post #Harvey mentioned in a comment yesterday would be helpful for this (and more details on handling the GatheringNodeData event).
Related
I create work items through the TFS api.
var type = project.WorkItemTypes["Bug"];
var workItem = new WorkItem(type)
{
History = "Created by OneTrueError incident #" + dto.OneTrueErrorIncidentId,
Title = dto.Title,
Description = dto.StackTrace,
};
workItem.Fields["Activity"].Value = dto.Activity;
workItem.Fields["Repro Steps"].Value = dto.StepsToReproduce;
workItem.Links.Add(new Hyperlink(someBaseUri + "/issue/" + dto.OneTrueErrorIncidentId));
workItem.Save();
At a later point I want to be able to fetch a specific work item by querying on a Hyperlink that I attached when creating the work item.
I can't figure out how to write that query. All examples I've found regarding links are for links to other work items or TFS resources. I have had no luck trying to modify those examples.
So how can I find a specific workitem using WIQL and a specific Hyperlink.Location?
Unfortunately, it's not able to directly use hyperlink url info in WIQL. You could only use Hyperlink Count field which returns the number of hyperlinks that are defined for the work item.
Reference Name=System.HyperLinkCount, Data type=Integer
As a workaround you may have to get a list of worktiems with links and go through all returned info to match the url that your attached when creating the work item. Then get the work item.
i want use watin to get list of elements in a webpage and change all the values
for example i want find all textboxes with "test" ID
and change their values
this is my code. but it only change one element, not all ( in my code i looked for elements via thir name )
IE ie = new IE("http://sample.net/");
ie.TableRow(Find.ByText(t => t.Contains("sample text"))).TextField(Find.ByName("second text")).TypeText("write this string");
ie.WaitForComplete();
in this code i find a text in a table, then i find text box (second text) , then it write "write this string"
but it i want to do this for all the similar elements
i tried with foreach but failed
anyone knows the right code?
I can see that you have targeted to a TableRow and used TextField which would be only a textfiled. You should be targeting parent and try to get all the text fields with your criteria.
I have tried with below code and worked for me. If you still unable to figure out the issue, you post the error/html source code.
IE ie = new IE("https://accounts.google.com/SignUp?service=mail&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F<mpl=default");
ie.WaitForComplete();
foreach (var txtEle in ie.Form(Find.ById("createaccount")).TextFields)
{
if (!string.IsNullOrEmpty(txtEle.Id))
{
if (txtEle.Id.Contains("Name"))
{
txtEle.TypeText("write this string");
}
}
}
ie.WaitForComplete();
I have a RelatedLinks property in one of my pages that I need to get the links/PageIds out from in the code behind of my macro-user control.
I can get the property like this
var current = Node.GetCurrent();
Response.Write("Output: " + current.GetProperty("RelatedLinks").Value);
But the output is empty. When I debug I can see that the Value includes some list content (like tags and such) some somehow nothing is printed.
My question is how I can get the value from this property into something like a collection of hyperlink objects.
I'm new to Umbraco and I's possible that I'm missing something essential here. Getting the content of other property types (like the Content Picker) works fine.
Thanks!
You can use this simple solution in Umbraco 7.+
Model.Content.GetPropertyValue<Umbraco.Web.Models.RelatedLinks>("relatedArticles");
this simply convert data to static type that is easy to use.
What data type is your related links set to, assuming its a content picker where you are getting the id of the related page you could first create a node form your current page's id then try and get the value from that node e.g.
var current = Node.GetCurrent();
var currentPage = Model.NodeById(current.Id);
var relatedLinks = currentPage.RelatedLinks;
or
var relatedLinks = GetProperty("RelatedLinks").Value;
when you debug you should be able to see all the properties of currentpage and check your alias as well to make sure its right (generally aliases dont start with a capital by default).
Try this umbraco.NodeFactory.Node.GetCurrent().GetProperty("RelatedLinks")
Solved it like this:
Document doc = new Document(Node.GetCurrent().Id);
umbraco.cms.businesslogic.property.Property relatedLinks = doc.getProperty("RelatedLinks");
XmlNode relatedLinksAsXml = relatedLinks.ToXml(new XmlDocument());
However it says that the Document class is obsolete and wants me to use Umbraco.Core.Models.Content instead. But this is MVC right? I'm trying to use webforms. Tried using the Node class as described in this thread but the Property object I got returned was of the wrong type and couldn't be converted to XML.
I'm trying to get data from the DOM from a document loaded into a Cocoa WebView control but it seems like the element's value is empty. I'm using MonoMac. The code I'm using (C#) is below:
var document = WebBrowser.MainFrameDocument;
if (document != null)
{
// GetAllChildren is a recursive extension function that iterates through a DomNode's
// ChildNodes property and returns a list of all of them
var textareaElements = document.GetAllChildren().OfType<DomHtmlElement>().Where(node => node.Name.Equals("TEXTAREA"));
foreach (var textarea in textareaElements)
{
var value = textarea.Value; // this is always ""
}
}
Do I need to do something to make sure the DOM reference I have to has the data entered into the webpage?
I rarely have to work with DOM but it seems to be the returned node is of type Element and the nodeValue will return a string only for a Text type.
From an Element you can try the TextContent, that does return the expected value for the bug report you mentioned.
Or you can access the Text node (it will be textarea.FirstChild.Value in your case) and that should also return the value you expect.
UPDATE
The original test case from the bug report did not show the real issue. A newer test case was provided and a fix is now available (on github monomac repo).
This appears to be a bug in the MonoMac implementation: https://bugzilla.xamarin.com/show_bug.cgi?id=7754
UPDATE: There is an active pull request that fixes this issue: https://github.com/mono/monomac/pull/109
I've been given a task to make a dynamic drop down which takes it's data[image and value id] from table. I am wondering if any of you came across this scenario or if any one can help me out in this I need help in concept and coding. Definitely any help is appreciated.
I see the example in jquery here is the link:
http://www.marghoobsuleman.com/jquery-image-dropdown
something like this but data is coming from table.
If you use the plugin that you found in the link, then basically what you will want to do is create the dropdown dynamically based on the table content. Without having more details of how your table is structured I can't give you exact details, but something like this should get you close (I'm going to assume there is a drop-down element already on the page somewhere called "select", and your table is called "table" with the image in field 0, and the text in field 1) Note: This hasn't really been tested.
var options = "";
$("#table tr").each(function() {
var imagePath = $(this).find("td:eq(0) img").attr("src");
var title = $(this).find("td:eq(1)").text();
options += '<option value="'+title+'" title="'+imagePath+'">'+title+'</option>';
});
$("#select").html(options);