943,597 Members | Top Members by Rank

Ad:
  • ASP Discussion Thread
  • Unsolved
  • Views: 1748
  • ASP RSS
Dec 26th, 2008
0

How to generate tree view in asp

Expand Post »
I want to generate a tree view using asp in which when I click the file (not the folder) the file should be deleted

I found this on net but how can I modify to delete a file when clicked on it.

http://classicasp.aspfaq.com/general...-from-asp.html

http://www.aspwebsolution.com/articl.../asp/index.htm
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
creativehacker is offline Offline
29 posts
since Jul 2007
Jan 5th, 2009
0

Re: How to generate tree view in asp

Here is a link for a very simple tree view: http://www.htmlforums.com/html-xhtml...ist-43732.html

It can be modified to allow for multiple tree views as shown in this example.

ASP Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2. function toggleBox(id){
  3. if (document.getElementById(id).style.display = = "") {
  4. show = "none";
  5. } else {
  6. show = "";
  7. }
  8. document.getElementById(id).style.display = show;
  9. }
  10. </script>
  11. </head>
  12. <body>
  13. <table width="100%" align="center">
  14. <tr>
  15. <td><a href="javascript:toggleBox(1)">+</a>&nbsp;<a href="" >Drive Letter</a></td>
  16. </tr>
  17. </table>
  18. <table width="100%" border="0" align="center" id="1" style="display: none;">
  19. <tr>
  20. <td bgcolor="#FFFFFF" width="30">&nbsp;</td>
  21. <td bgcolor="#FFFFFF" width="*">
  22. &nbsp;<a href="javascript:toggleBox(2)">+</a>&nbsp;<a href="" >Folder</a></td>
  23. </tr>
  24. </table>
  25. <table width="100%" border="0" align="center" id="2" style="display: none;">
  26. <tr>
  27. <td bgcolor="#FFFFFF" width="70">&nbsp;</td>
  28. <td bgcolor="#FFFFFF" width="*">&nbsp;
  29. <a href="../drive.asp?operator=Delete&file=C:\folder\filename.txt">File</a></td>
  30. </tr>
  31. </table>
  32. </body>
  33. </html>

So now with an easy to use tree the next thing you might want to do is use images instead or with the names in the tree as follows:

ASP Syntax (Toggle Plain Text)
  1. %><td width="10"><a href="javascript:toggleBox(<%= intCount1 %>)">
  2. <img border="0" src="../Graphics/Folder.gif"></a><a href="" ></a></td><%

Also note that a variable “intCount1” is used instead of hard coding the javascript:toggleBox value, a variable can also be used with the ID to make this code very dynamic with some loops.

Now for the deleting file: A static tree makes no sense as you will need to change the code each time a file is deleted. For a dynamic list you will need to search the drive and write the file names into variables in the anchors. Start your tree with the root C:\ (or whatever your root/folder that you want to start is) Then search for folder names and files inside the folders as you loop through this write the values into the anchors. Example:
ASP Syntax (Toggle Plain Text)
  1. <a href="../drive.asp?operator=Delete&file=<%= Path1 %>
  2.  
Path1 will be the path to the file example: (C:\folder\filename.txt).

So now that the tree is created when you click on the text or graphic corresponding to the path you will be directed to the html link with a querystring containing two values. The first value (in this case operator) will give a conditional statement, the second (File) will point to the path of the file you wish to delete.

ASP Syntax (Toggle Plain Text)
  1. If operator = Delete Then
  2. Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
  3. objFSO.DeleteFile("C:\folder\filename.txt")
  4. End if
With C:\folder\filename.txt being the value contained in Path1

My assumption being that you are asking about asp pages is that you will be using vbscript and are on a windows server.

For some more information on FileSystemObjects check out the following links
http://www.microsoft.com/technet/scr...nda/files.mspx

http://www.activexperts.com/activmon...sfolders/files
Reputation Points: 10
Solved Threads: 1
Newbie Poster
closetosane is offline Offline
12 posts
since Jan 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP Forum Timeline: hi
Next Thread in ASP Forum Timeline: Session problem in asp





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC