Hi
The autocomplete extender works with a webservice or a page method decorated with webservice method and script service method attributes. To read an XML with that much record from file and search for each character typed is a huge work. An in memory collection may help a little. Whether xpath or linq, it has to be executed after the data loaded into memory. So if you have that already in memory this overhead can be avoided. But remember this is again a trade off between speed and memory consumption. The in memory collection permanently occupy some memory space. Again it is a string collection definitely occupy more space. The key parameter you can set in the autocomplete markup is
MinimumPrefixLength
. It should be minimum 3 to avoid a costly search.
Another way store the xml in sql server and when needed retrieve it and can use the xpath. Which will be more faster than file based. Refer this link.
http://msdn.microsoft.com/en-us/library/ms187508%28v=sql.90%29.aspx[
^]
Well google give more information if you use key words "ado.net xml best practice".
You asked for a code. Well here is the code for in memory collection
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class TestService : System.Web.Services.WebService {
private static string[] suggestions;
[WebMethod]
public string[] getSuggestions(string prefixText, int count)
{
if (suggestions == null)
{
setSuggestions();
}
return suggestions.Where(x => x.StartsWith(prefixText)).ToArray<string>();
}
[WebMethod]
public void ResetSuggestions()
{
setSuggestions();
}
private void setSuggestions()
{
IList<string> templist = new List<string>();
templist.Add("happy");
templist.Add("world");
suggestions = templist.ToArray();
}
}
But the important thing
don't just rely on the code blindly. Follow my guidelines above, read more and decide which one fit for your case. Try yourself and then come back if you have any problem with code.