1

So, here is the need.

I visit a few directories every day and my desktop is full of shortcuts. I want to eliminate this. So I came up with the idea that I will use a simple web page that will have a list of directory names (these names will be from the local datasource) that will auto-complete as I type and when I click them, they should open the directory. It's more like clicking on it an opening a URL. You get the idea right?

I have used the code from jQuery UI.

<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="utf-8">
<title>jQuery UI Autocomplete - Default functionality</title>
<link rel="stylesheet" href="css/redmond/jquery-ui-1.8.20.custom.css">
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/jquery-ui-1.8.20.custom.min.js"></script>

<link rel="stylesheet" href="../demos.css">
<script>
$(function() {
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Python",
"Ruby",
"Scala",
"Scheme"
];
$( "#tags" ).autocomplete({
source: availableTags
});
});
</script>
</head>
<body>

<div class="demo">
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags" />
</div>

</div><!-- End demo -->



</body>
</html>

Thanks in advance.

williamtell
  • 301
  • 5
  • 17

1 Answers1

0

if it's asp.net then i would have done like this

markup :

<asp:TextBox runat="server" ID="txtFileS" ></asp:TextBox>

Jquery :

$(document).ready(function() {
            $('#txtFileS').autocomplete({
                source: function(request, response) {
                    $.ajax({
                    url: "Default.aspx/GetFileList",
                        data: "{ 'query': '" + request.term + "' }",
                        dataType: "json",
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        dataFilter: function(data) { return data; },
                        success: function(data) {
                            response($.map(data.d, function(item) {
                                return {
                                    value: item
                                };
                            }));
                        }
                    });
                }

            });
        }); 

Server Side method :

   [WebMethod]
    public static string[] GetFileList(string query)
    {
        var s = Directory.GetFiles("C:\\").ToArray();
        return s;  // you need to filter the array according to the query. 
    }

PS : you need to filter the query as you type. in Server side code.

Ravi Gadag
  • 15,735
  • 5
  • 57
  • 83
  • No ASP.NET. It is basic HTML and jQuery and runs on other computers too. Nothing to do with servers. – williamtell May 14 '12 at 11:06
  • @williamtell you cant do that with javascript, you need to use sockets, file stream to access the content http://stackoverflow.com/questions/2924935/list-files-in-a-directory-using-only-javascript – Ravi Gadag May 14 '12 at 11:11
  • Open C Dir opens the C directory. I want to have several links like these and open different directories. I am not doing anything complex. Instead of using many shortcuts, I am trying to use a web page and open different directories in a machine. – williamtell May 15 '12 at 05:57