Why the where clause is not working on sharepointsearch? - asp.net

StringBuilder xmlString = new StringBuilder(
"<QueryPacket xmlns='urn:Microsoft.Search.Query'>"
+ "<Query><SupportedFormats><Format revision='1'> urn:Microsoft.Search.Response.Document:Document"
+ "</Format></SupportedFormats><Context>"
+ " <QueryText language='en-US' type='FQL'>");
// this adds the search free form text
xmlString.Append("Earth");
query.Append(
"</QueryText></Context>"
+ "<Properties>"
+ "<Property name='Name'/>"
+ "<Property name='Department' />"
+ "<Property name='Property1' />"
+ "<Property name='Property2' />"
+ "<Property name='Property3' />"
+ "<Property name='Property4' />"
+ "<Property name='Property5' />"
+ "</Properties>"
+ "<Where>"
+ "<IsNotNull><FieldRef Name='Name'></FieldRef></IsNotNull>"
+ "<And><IsNotNull><FieldRef Name='Property1'></FieldRef></IsNotNull></And>"
+ "</Where>"
+ "</Query></QueryPacket>"
);
QueryServiceSoapClient.QueryEx(query)
I am getting data with the null/empty value on Name and Property1 column.
Why where is not working?

It looks like your where clause is not properly formatted as #Damith suggested. Why dont you build your query using FAST Search for Sharepoint MOSS 2010 Query Tool. Its really quick and efficient way to work on this kind of tasks.

+ "<And><IsNotNull><FieldRef Name='Property1'></FieldRef>"+"</IsNotNull>And>"
In this line after IsNotNull you missing </ so the line should be
+ "<And><IsNotNull><FieldRef Name='Property1'></FieldRef>"+"</IsNotNull></And>"

Your issue is that you've got the <and> clause sitting in the wrong place.
It should look like this:
<Where>
<And>
<IsNotNull>
<FieldRef Name='Name'>
</FieldRef>
</IsNotNull>
<IsNotNull>
<FieldRef Name='Property1'></FieldRef>
</IsNotNull>
</And>
</Where>
It's a weird place to have to put the and clause, I know, but that's how CAML works. I strongly recommend using a program such as CAMLQueryHelper if you're going to use CAML instead of Linq.

Related

Posting a collection - is empty/null when adding a class on the table row

I have a simple ASP.NET MVC application, where our users have a table which has some options to edit some settings.
This table is build dynamically using jQuery since this is some legacy code. The code to make the table is:
function setInvoiceTable(result) {
result.OverduesPaged.forEach(function (item, index) {
var externalName = 'OverduesPaged[' + index + '].ExternalInvoiceGuid';
var debtorName = 'OverduesPaged[' + index + '].Debtor';
var visibleName = 'OverduesPaged[' + index + '].IsSelected';
var externalInvoiceGuidField = '<input type=\'hidden\' value=\'' + item.ExternalInvoiceGuid + '\' name=\'' + externalName+ '\' />';
var debtorField = '<input type=\'hidden\' value=\'' + item.Debtor + '\' name=\'' + debtorName + '\' />';
var invisibleField = '<input type=\'hidden\' value=\'false\' name=\'' + visibleName + '\' id=\'' + visibleName + '\' /></label>';
var visibleField = '<label><input type=\'checkbox\' value=\'true\' name=\'' + visibleName + '\' id=\'' + visibleName + '\' /> Start sag';
var insertStr = "<tr>" +
"<td>" + externalInvoiceGuidField + debtorField + visibleField + invisibleField + "</td>" +
"<td>" + item.InvoiceId + "</td>" +
"<td>" + item.Debtor + "</td>" +
"<td>" + item.DateString +"</td>" +
"<td>" + item.DaysSinceDueString +"</td>" +
"<td>" + item.GrossAmountString + "</td>" +
"<td>" + item.RemainderAmountString + "</td>" +
"</tr>";
$('#accounting_invoices_table').append(insertStr);
});
}
When I POST, this works perfectly for us. We have an endpoint in our controller which has this signature:
[System.Web.Mvc.HttpPost]
public ActionResult StartDebtCollectionCases(UpcomingDashboardViewModel vm)
{
// code
}
The collection I'm building is the OverduesPaged which is a part of our view model:
public class UpcomingDashboardViewModel
{
public List<OverdueUpcomingInvoiceViewModel> OverduesPaged { get; set; }
// more stuff not relevant to question
}
This is my challenge:
I've added a css class to the <tr> row like this:
// new code added
var removeClass = 'ok';
if (item.IsAlreadyCase) {
visibleField = '<label type="text">Allerede startet</label>';
removeClass = 'remove';
} else if (item.IsBlocked) {
visibleField = '<label type="text">Sat i bero</label>';
removeClass = 'remove';
}
else if (item.Currency != "DKK") {
visibleField = '<label type="text">Faktura skal være dansk valuta</label>';
removeClass = 'remove';
}
var insertStr = "<tr class='" + removeClass + "'>" +
"<td>" + externalInvoiceGuidField + debtorField + visibleField + invisibleField + "</td>" +
// rest of code from above
Now I end up with a table exactly like before, but with a class which is either OK or REMOVE.
However, when I now do the POST, the whole collection, OverduesPaged, is null/empty:
I tried to add the class to the <td> instead, but then the collection was null/empty.
Any ideas what is wrong here?
The issue is not related to adding the class name itself, but rather the invalid html that you generating if ant of the code in the if or else if blocks are executed. In those blocks you are creating <label> element with a closing tag, but no input (its not clear if you need the checkbox or not in those cases), so when you combine visibleField + invisibleField you get unbalanced <label> tags (visibleField has opening and closing tags, but invisibleField only has a closing </label> tag.
You code in the if blocks to generate visibleField would need to be similar to what you generate in the original code - i.e. just an opening <label> with the html for the checkbox.
As you have acknowledged in the comments, this is very fragile and error prone code that is difficult to debug. As you are intending to rewrite it, consider returning a partial view in your ajax call (that is strongly bound to the model), or if you need to return Json, then consider a hidden template (outside the <form> tags) that you clone and update in the script, for example
<div id="newrow" style="display:none">
<tr>
<td>
<input class="invoice" type="hidden" name="OverduesPaged[#].ExternalInvoiceGuid value />
<input class="debtor" type="hidden" name="OverduesPaged[#].Debtor value />
....
</td>
....
</tr>
</div>
and then you script becomes
var table = $('#accounting_invoices_table');
result.OverduesPaged.forEach(function (item, index) {
var clone = $('#newrow').clone();
// Update indexer
clone.html($(clone).html().replace(/\[#\]/g, '[' + index + ']'));
// Update values
clone.find('.invoice').val(item.ExternalInvoiceGuid);
....
table.append(clone.html());
});
As a side note, your existing id attributes are invalid because they contain ., [ and ] characters (if you attempted to use these in jQuery selectors, they would fail (for example the . will be interpreted as a class name), so they should be omitted in the html

Tag type as string variable in selenium

How to pass tag type as a string variable in selenium?
suppose I am having given example:
By.cssSelector: li[__idx='0']
for given example I tried below part
webElement.findElement( By.cssSelector( "'" + tag + "'['" + property + "'='" + indexNumber + "']" ) )
where tag is li and __idx is property.
I am getting error as " Could not locate element with locator ". but if I tried as below then its working correctly.
webElement.getElement().findElement( By.cssSelector( "li[__idx='" + indexNumber + "']" ) )
Is there any syntactical mistake am doing ?
webElement.find( "" + tag + "[" + property + "='" + indexNumber + "']" );
This is the correct way to solve the issue.

How can I hide sb.append in email if field is empty in asp.net?

In one of my forms the answers are optional. How can I get it so that only the fields that have been filled in show on the email that the form sends out?
Code example:
sb.Append("<br /><br /><br />Email from: " + txtEmail.Text + "\n");
sb.Append("<br /> <br />Site Name : " + txtSiteName.Text + "\n");
sb.Append("<br />Contract number : " + txtContractno.Text + "\n");
sb.Append("<br />Department : " + txtDepartment.Text + "\n");
If no one puts in their department, I dont want the heading and blank space where the answer should go to appear on the email. However if the department is filled in on the form, then I do want it to appear on the email. What should I do?
Two simplest options would be:
if (!string.IsNullOrWhitespace(txtDepartment.Text))
sb.Append("<br />Department : " + txtDepartment.Text + "\n");
...
or
sb.Append((!string.IsNullOrWhitespace(txtDepartment.Text)) ? "<br />..." : string.Empty);
Of which the first is probably preferable as it skips the call to append completely if the string's not there.

Inner query in fusion tables

This query will take input from three drop down box and a text box and it work's fine as expected.But my requirement is i need to use another three drop down box and a text in order to query much deeper.So,i need to hold the result of first query and also second query.How should i do.Help me.
That another three drop down box value is also obtained from the same variable's as 'operator','textvalue','querypass'.
function querymap()
{
var operator=document.getElementById('operatorstring').value.replace(/'/g, "\\'");
var textvalue=document.getElementById("text-value").value.replace(/'/g, "\\'");
var querypass=document.getElementById('query-pass').value.replace(/'/g, "\\'");
var searchStringe = document.getElementById('Search-stringe').value.replace(/'/g, "\\'");
var searchString = document.getElementById('search-string').value.replace(/'/g, "\\'");
{
layer.setQuery("SELECT 'geometry'," + querypass + " FROM " + tableid + " WHERE " + querypass + " " + operator + " '" + textvalue + "' AND VillageName = '"+ searchStringe+"'");
}
}
You can have as many AND conditions in your query as you want. No reason not to also check e.g. textvalue2, querypass2, searchString2, etc. and add them to your query. See this setQuery() answer which may give you some ideas. You'll need to set all your search conditions each time you call layer.setQuery() or layer.setOptions({query: ...});

The best browser detection solution in ASP.NET 4.0

I googled this topic and I came across with three different ways to configure browser capabilities: browscap.ini, browserCaps element in web.config and .browser files in App_Browsers. I thought .browser files is the latest way, but I don't seem to find up-to-date files. But I found quite fresh browscap.ini from http://browsers.garykeith.com/downloads.asp.
My first priority is to exclude common crawlers from the visitor stats. The second priority is to detect browser and os with correct versions (e.g. Opera 11 / Win7).
Are there any libraries I could use? Is browscap.ini still a valid way and is it possible to use it without access to system files? Where can I find up-to-date .browser files?
more info : http://msdn.microsoft.com/en-us/library/3yekbd5b.aspx
Have you checked this :
System.Web.HttpBrowserCapabilities browser = Request.Browser;
string s = "Browser Capabilities\n"
+ "Type = " + browser.Type + "\n"
+ "Name = " + browser.Browser + "\n"
+ "Version = " + browser.Version + "\n"
+ "Major Version = " + browser.MajorVersion + "\n"
+ "Minor Version = " + browser.MinorVersion + "\n"
+ "Platform = " + browser.Platform + "\n"
+ "Is Beta = " + browser.Beta + "\n"
+ "Is Crawler = " + browser.Crawler + "\n"
+ "Is AOL = " + browser.AOL + "\n"
+ "Is Win16 = " + browser.Win16 + "\n"
+ "Is Win32 = " + browser.Win32 + "\n"
+ "Supports Frames = " + browser.Frames + "\n"
+ "Supports Tables = " + browser.Tables + "\n"
+ "Supports Cookies = " + browser.Cookies + "\n"
+ "Supports VBScript = " + browser.VBScript + "\n"
+ "Supports JavaScript = " +
browser.EcmaScriptVersion.ToString() + "\n"
+ "Supports Java Applets = " + browser.JavaApplets + "\n"
+ "Supports ActiveX Controls = " + browser.ActiveXControls
+ "\n"
+ "Supports JavaScript Version = " +
browser["JavaScriptVersion"] + "\n";
TextBox1.Text = s;
I found a user agent parser from http://user-agent-string.info/ and it seems to be good enough for my purposes.
Just so no one else goes down that dark path, be aware that even the jQuery team recommend that you DO NOT use jQuery.browser object:
"The $.browser property is deprecated in jQuery 1.3"
The best answer is feature detection, not browser detection! This is particularly true in the day where Firefox & Chrome are putting out releases ever few months and mobile browser use is growing. Use Modernizr (http://Modernizr.com) or an equivalent library to detect the features you are interested in.
So far I've used http://api.jquery.com/jQuery.browser/ for client side detection.

Resources