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/how-do-i-generate-a-treeview-from-asp.html

http://www.aspwebsolution.com/articles/coder4life/treeview/asp/index.htm

Here is a link for a very simple tree view: http://www.htmlforums.com/html-xhtml/t-how-do-i-make-an-expandable-list-43732.html

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

<script type="text/javascript">
  function toggleBox(id){
    if (document.getElementById(id).style.display = = "") {
       show = "none";
  } else {
       show = "";
		}
    document.getElementById(id).style.display = show;
	}
</script>
</head>
<body>
<table width="100%" align="center">
   <tr>
      <td><a href="javascript:toggleBox(1)">+</a>&nbsp;<a href="" >Drive Letter</a></td>
   </tr>
</table>
<table width="100%" border="0" align="center" id="1" style="display: none;">
   <tr>
      <td bgcolor="#FFFFFF" width="30">&nbsp;</td>
      <td bgcolor="#FFFFFF" width="*">
      &nbsp;<a href="javascript:toggleBox(2)">+</a>&nbsp;<a href="" >Folder</a></td>
   </tr>		
</table>
<table width="100%" border="0" align="center" id="2" style="display: none;">
   <tr>
      <td bgcolor="#FFFFFF" width="70">&nbsp;</td>
      <td bgcolor="#FFFFFF" width="*">&nbsp;
      <a href="../drive.asp?operator=Delete&file=C:\folder\filename.txt">File</a></td>
   </tr>
</table>		
</body>
</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:

%><td width="10"><a href="javascript:toggleBox(<%= intCount1 %>)">
           <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:

<a href="../drive.asp?operator=Delete&file=<%= Path1 %>

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.

If operator = Delete Then
    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    objFSO.DeleteFile("C:\folder\filename.txt")
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/scriptcenter/resources/qanda/files.mspx

http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/filesfolders/files

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.