by

Display List Of Files From Server Folder In Asp.net Gridview

Display List Of Files From Server Folder In Asp.net Gridview 3,9/5 6580 votes

Question:

Get Filenames From Folder in Gridview Control in ASP.Net. The names of files in a specified directory or returns a string array of file names. From MyFiles. Normally get all the images from a folder and bind to the GridView. Get only a specified extension (such as only.JPG files) and bind to the GridView. GridView Script will be same as above. Get the files with Multiple extensions (such as files with.JPG,.GIF and.PNG) and bind to the GridView. Extract Files from Folder and Bind with Asp.Net GridView – C# and Vb.Net. Once, you choose a particular File type you will click a button to postback information to the server. Files will be extracted using classes like DirectoryInfo () and FileInfo () of System.IO namespace. We can then bind the list of files, f either particular type or all the files in a folder, to a GridView control. Display Files In GridView From Server Directory Asp.Net This Example Show How To Display Files Directory Sub Directories In GridView From Server Folder In Asp.Net application using C# and Vb.Net. We need to use DirectoryInfo class under System.IO namespace.

How can I display the files and sub folders on the server in Folder View?


Answer:

Folder View use unordered list for building the tree. You have to construct the unordered list, in order to display the files and sub-folders of particular folder of your server into a tree.

To do that you can use the following code to get the files and sub-folder and build the list:
(It is provided both for ASP and PHP. Chose the appropriate one depending on your server-side language)

* ASP (VBScript)

If you use ASP VBScript for server-side language, you could add the following code to your page:

<%
Sub ListFolder(path)
Dim fs, folder, file, item
Set fs = CreateObject('Scripting.FileSystemObject')
Set folder = fs.GetFolder(path)
'Display the target folder.
Response.Write('<li>' & folder.Name)
Response.Write('<ul>' & vbCrLf)
If (folder.Files.Count > 0)OR(folder.SubFolders.Count >0) Then
'Display a list of sub folders.
for each item in folder.SubFolders
ListFolder(item.Path)
next
'Display a list of files.
For each item in folder.Files
Response.Write('<li>' & item.Name & '</li>' & vbCrLf)
Next
End If
Response.Write('</ul>' & vbCrLf)
Response.Write('</li>' & vbCrLf)
End Sub
%>

To use the code into your Folder View, you just have to replace the automatically generated unordered list with the execution of the ListFolder function.
Upload is the name of the folder which content will be displayed into the tree.

For example:

<script language='JavaScript' type='text/javascript'>
<!--
dmxListToTree({
bullets : 'plusminus',
icons : true,
struct : false,
objId : 'FolderView'
});
//-->
</script>
<ul>
<% ListFolder(Server.MapPath('Upload')) %>
</ul>

* PHP

If you use PHP for server-side language, you could try the following code:

Collection download game 7 sins for android psp equipped with a very telling tips here. Whatever you find on this blog is guaranteed to meet, including the game apk, android ppsspp games and a full tutorial about android. Download game seven sins for android download. Collection 7 sins game download mod for android equipped with a very telling tips here. Whatever you find on this blog is guaranteed to meet, including the game apk, android ppsspp games and a full tutorial about android.

<?php
function ListFolder($path)
{
//using the opendir function
$dir_handle = @opendir($path) or die('Unable to open $path');
//Leave only the lastest folder name
$dirname = end(explode('/', $path));
//display the target folder.
echo ('<li>$dirnamen');
echo '<ul>n';
while (false ! ($file = readdir($dir_handle)))
{
if($file!='.' && $file!='.')
{
if (is_dir($path.'/'.$file))
{
//Display a list of sub folders.
ListFolder($path.'/'.$file);
}
else
{
//Display a list of files.
echo '<li>$file</li>';
}
}
}
echo '</ul>n';
echo '</li>n';
//closing the directory
closedir($dir_handle);
}
?>

To use the code into your Folder View, you have to replace the automatically generated list with the execution of the ListFolder function.

For example:

<script language='JavaScript' type='text/javascript'>
<!--
dmxListToTree({
bullets : 'plusminus',
icons : true,
struct : false,
objId : 'FolderView'
});
//-->
</script>
<ul>
<?php ListFolder('Upload'); ?>
</ul>

How

Notes: Have in mind that the above code will display all the content into defined folder (all files and the sub-folders with their content).


DISCLAIMER:
This is extra complimentary content which purpose is to show additional usage that is not part of the product, i.e. it suggests tips for extending the functionality of the product by the users themselves. It is provided 'as is', without warranty of any kind, express or implied , including but not limited to the warranties of merchantability, fitness for a particular purpose and nonfringement of third party rights.
DMXzone does not take responsibility to support the suggested content to be fully compatible and working as intended and does not provide support for extended functionality which is not included in the current release of the extension.
It is highly recommended that only more advanced developers use it.

Download The Most Advanced Web App Builder in the world!

Wappler is the DMXzone-made Dreamweaver replacement and includes the best of our powerful extensions, as well as much more!

Download Files From Server To Server

Download now for FREE

Extension Manager

The DMXzone Extension Manager is an application that will make your life easier. In a blink of an eye you can install, update and manage your extensions and templates.

Sites to download free games for laptop. All in all these all games are for free and you can easily download them going on to their website.

Get it Now

Latest FAQs

  • How to use and display current date with the 'Date and Time' componentLearn how to display the current date on your page
  • How to make your App Connect page SEO friendlyLearn how to make App Connect Pages SEO friendly
  • Styling Bootstrap 3 Dynamic Paging Generator 2Learn how to style the paging created with Bootstrap 3 Dynamic Paging Generator 2
  • Can Not Install Extensions in DMXzone Extension ManagerSend us the debug file and we will help you out
  • Dreamweaver CC2017 not detected in DMXzone Extension ManagerHow to fix missing Dreamweaver CC2017
  • Does DMXzone Extension Manager Support Non-DMXzone Extensions?How to install and update non-DMXzone extensions
  • Styling the Universal CSS Navigation MenuLearn the Basics of Universal CSS Navigation Menu Styling
  • Spry Validation not Working with Pure PHP Upload 2I Cannot get the Validation to Work with Pure PHP Upload
  • Using DMXzone New Extensions ForumsLearn how to use our new forums
  • When installing an exension I get a message: wrong version of DW - version 7 or higher is requiredAssociate the .mxp or .zxp files with the right DW version Extension Manager

How To Recover Deleted Files From Server

Most Read FAQs

  • PHP - Getting notice Undefined index
  • Using DMXzone New Extensions ForumsLearn how to use our new forums
  • Where do I find my Serial Number?
  • Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
  • The media could not be loaded, either because the server or network failed or because the format is not supportedI'm getting an error saying: 'The media could not be loaded, either because the server or network failed or because the format is not supported.'
  • Calling an Oracle Stored Procedure
  • Upload Large Files on Windows 2003 server
  • ASP Timeout on Large Files or Slow Connection
  • Clearing Dreamweaver's cache
  • How do I install GD in windows?

Copy Files From Server To Local Machine

Best Rated FAQs

Java Load Files From Server

  • Optional Upload?
  • Can I use this EXT without ultraDev
  • Delete Dynamically Named Folder
  • Can I upload to multiple directories?
  • Check Form not Working
  • Content from database?
  • Adjust scrolling speed
  • Persistent FW/DW popup menus?
  • Deleting a previously uploaded file
  • What kind of content can I put in the scroller?