I am having trouble displaying data using jQuery File Tree plugin. No matter what I use for ‘root’, it always uses ” and displays content of C drive!
I am using aspx (with code behind that I am not using) and a master page.
<div class="col-md-12" id="divAIMDocs"> </div> <script> function openFile(file) { // do something with file alert(file); } $(document).ready(function () {debugger $('#divAIMDocs').fileTree({ root: decodeURI(uploadFolder), script: '../assets/vendor/jquery_FileTree/connectors/jqueryFileTree.aspx', expandSpeed: 1000, collapseSpeed: 1000, multiFolder: false }, function(file) { openFile(file); }); }); </script>
I added a breakpoint in venodr’s js file (below) as well as the ‘connector’ script:
$(this).each( function() { function showTree(c, t) {debugger <-- this shows 't' as '' $(c).addClass('wait');
and in connector script, jqueryFileTree.aspx:
string dir; if(Request.Form["dir"] == null || Request.Form["dir"].Length <= 0) <-- always null dir = "/"; else dir = Server.UrlDecode(Request.Form["dir"]);
I then tried to hard code ‘root’ value to ‘D:SomeFolder’:
$(document).ready(function () {debugger $('#divAIMDocs').fileTree({ root: 'D:SomeFolder', script: '../assets/vendor/jquery_FileTree/connectors/jqueryFileTree.aspx', ...
and I see in function showTree parameter ‘t’ is now actually seeing ‘D:SomeFolder’ but connector still says Request.Form[“dir”] is null and proceeds to show content of C drive.
What a I doing wrong here?
Advertisement
Answer
As I thought, the problem was with Request.Form[“dir”]. I found this article and it pointed to an issue I wouldn’t have thought of. It is due to using FriendlyURL feature of .NET (i.e. has nothing to do with jQuery File Tree plugin).
“The HTML form in this example is designed to post to Receiver.aspx, and the Friendly URLs will take requests that include the file extension and issue an HTTP 301 – Moved Permanently response, directing the browser to make a new (GET) request for the same resource without the file extension.”
The solution was to comment out below line in RoutConfig.cs file:
public static void RegisterRoutes(RouteCollection routes) { var settings = new FriendlyUrlSettings(); //settings.AutoRedirectMode = RedirectMode.Permanent; routes.EnableFriendlyUrls(settings); }
Original POST gets overwritten by subsequent GET and data is lost.
Request.Form is populated only if the page is loaded though a form POST.