I am trying to display 5 levels of document library in a tree view to show all the files within all folders and sub folders. How can I achieve this task?
You can use server side object model for this.
There is very good example of your problem:
Sometime back I created a tree view collapsible menu for SharePoint Online. Following is the URL