[RESOLVED]Razor Web Pages Directory.GetFiles with Jquery Autocomplete

Having successfully integrated an autocomplete function to one of my projects using mikesdotnetting article

HERE
, (nice facelift on the site btw Mike), I am now trying to implement the same but using a Directory.GetFiles command to autocomplete a filename lookup.

I realise this isn’t confined to Webmatrix & Web Pages but as that is the environment I am working in I thought I’d see if anyone had successfully achieved this?

Current code is below:

Main Page:

        <div id="searchInput" class="searchInput">
        <br />
            <div id="searchdiv">Reg. Search: &nbsp<input type="text" id="search" name="search" class="search" /></div>
        <br />
        </div>
        <script>
            $(function () {
                $('.search').autocomplete({ source: '/lookups/lookup',
                                          minLength: 4 });
            });
        </script>

lookups/lookup.cshtml

@{
    var files = (@"\serverinsurance$InformationBLANK FORMS - HEADER SHEETSSWOCLOSED CLAIMS");
    foreach(var file in files){
        reg = file;
    }
    var term = Request["term"] + "%";
    var result = Directory.GetFiles(files,term, SearchOption.AllDirectories);
    var data = result.Select(p => new{label = p.???});
    Json.Write(data, Response.Output);
}

As you can see above, I have placed 3 ?’s where I am a bit stumped.

Using a DB Query, this would be the field to pull out of the DB but in this situation I am struggling to figure out what to replace it with?

Any help or points in the right direction would be great.

Cheers

This thread has been answered via
THIS
 thread.

Leave a Reply