<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AutoCompleteWebService.aspx.cs" Inherits="WebService1.AutoCompleteWebService" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="sm1" runat="server" EnablePartialRendering="false" /> <ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender1" TargetControlID="txtFileName" ServiceMethod="GetSuggestions" ServicePath="~/FileService.asmx" MinimumPrefixLength="1" runat="server" /> <asp:TextBox ID="txtFileName" runat="server"></asp:TextBox> </div> </form> </body> </html>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using System.IO; namespace WebService1 { [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] public class FileService : System.Web.Services.WebService { [WebMethod] public string[] GetSuggestions(string prefixText, int count) { DirectoryInfo dir = new DirectoryInfo("c:\\windows"); return dir .GetFiles() .Where(f => f.Name.StartsWith(prefixText)) .Select(f => f.Name) .ToArray(); } } }
Toolkitscript
scriptmanager
[System.Web.Script.Services.ScriptService]
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)