473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How do you get a list of files from server folder to display on in a list control

I'm using .net 1.1 trying to get a list of files in folder on the server.
The user would select the file they want to download from a DropDownList.
Can someone tell me how this should be done? I can't find the right class
or object to use. Is it the File class or the FolderBrowser? Stuck like
Chuck!!! Any suggestions welcome. Thanks.
Oct 17 '06 #1
4 5238

You can use FileSystemObject like this.

<%
Set objFSO=Server.CreateObject("Scripting.filesystemob ject")
Set objFold=objFSO.GetFolder("E:\admin\uploads")
Set objfiles=objFold.files
%>
and then generating my drop down using

<select name="productThumb" id="productThumb">
<option><%For Each objFile in objFolder.files
objFile.Name
Next
%></optio

Shahzad Godil

Karachi-Pakistan.
"ma********@yahoo.com" <Ma********@yahoo.comwrote in message
news:ev*****************@newssvr27.news.prodigy.ne t...
I'm using .net 1.1 trying to get a list of files in folder on the server.
The user would select the file they want to download from a DropDownList.
Can someone tell me how this should be done? I can't find the right class
or object to use. Is it the File class or the FolderBrowser? Stuck like
Chuck!!! Any suggestions welcome. Thanks.

Oct 17 '06 #2
Hi,

Shahzad Godil wrote:
You can use FileSystemObject like this.

<%
Set objFSO=Server.CreateObject("Scripting.filesystemob ject")
Set objFold=objFSO.GetFolder("E:\admin\uploads")
Set objfiles=objFold.files
%>
and then generating my drop down using

<select name="productThumb" id="productThumb">
<option><%For Each objFile in objFolder.files
objFile.Name
Next
%></optio

Shahzad Godil

Karachi-Pakistan.
Are you seriously proposing using the FileSystemObject in an ASP.NET
environment? That's sub-optimal to say the least

To the OP: You get a list of files in a folder using the
System.IO.DirectoryInfo class.

For example:

DirectoryInfo dir = new DirectoryInfo( "c:\\temp" );
if ( dir.Exists )
{
FileInfo[] filesInDir = dir.GetFiles();
}

http://msdn2.microsoft.com/en-us/lib...ctoryinfo.aspx

HTH,
Laurent

>

"ma********@yahoo.com" <Ma********@yahoo.comwrote in message
news:ev*****************@newssvr27.news.prodigy.ne t...
>I'm using .net 1.1 trying to get a list of files in folder on the server.
The user would select the file they want to download from a DropDownList.
Can someone tell me how this should be done? I can't find the right class
or object to use. Is it the File class or the FolderBrowser? Stuck like
Chuck!!! Any suggestions welcome. Thanks.


--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Oct 17 '06 #3
Thanks for the responses...

This is what I got using a DropDownList and a Button.

Dim parentfolder As String = "recipes"
Dim myDir As New DirectoryInfo(Server.MapPath(parentfolder))
Me.DDLFileNames.DataSource = myDir.GetFiles("*.doc")
Me.DDLFileNames.DataBind()
Session("FilePath") = myDir.ToString

**Click the download button and...
Session("FileName") = Me.DDLFileNames.SelectedItem.ToString
Response.Redirect("FileDownload.aspx")

**page load in FileDownload.aspx
Dim filename As String = DirectCast(Session("FileName"), String)
Dim filepath As String = DirectCast(Session("FilePath"), String)
Dim fullpath As String = filepath + "\" + filename
Response.Clear()
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", _
"attachment; filename=""" & filename & """")
Response.Flush()
Response.WriteFile(fullpath)
Session.Abandon()

This works great running at home but when I upload it to my server the
file(aword.doc) gets downloaded and it is empty. Any ideas why that is?
Thanks again.
"Laurent Bugnion" <ga*********@bluewin.chwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Hi,

Shahzad Godil wrote:
>You can use FileSystemObject like this.

<%
Set objFSO=Server.CreateObject("Scripting.filesystemob ject")
Set objFold=objFSO.GetFolder("E:\admin\uploads")
Set objfiles=objFold.files
%>
and then generating my drop down using

<select name="productThumb" id="productThumb">
<option><%For Each objFile in objFolder.files
objFile.Name
Next
%></optio

Shahzad Godil

Karachi-Pakistan.

Are you seriously proposing using the FileSystemObject in an ASP.NET
environment? That's sub-optimal to say the least

To the OP: You get a list of files in a folder using the
System.IO.DirectoryInfo class.

For example:

DirectoryInfo dir = new DirectoryInfo( "c:\\temp" );
if ( dir.Exists )
{
FileInfo[] filesInDir = dir.GetFiles();
}

http://msdn2.microsoft.com/en-us/lib...ctoryinfo.aspx

HTH,
Laurent

>>

"ma********@yahoo.com" <Ma********@yahoo.comwrote in message
news:ev*****************@newssvr27.news.prodigy.n et...
>>I'm using .net 1.1 trying to get a list of files in folder on the
server. The user would select the file they want to download from a
DropDownList. Can someone tell me how this should be done? I can't find
the right class or object to use. Is it the File class or the
FolderBrowser? Stuck like Chuck!!! Any suggestions welcome. Thanks.

--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch

Oct 19 '06 #4
Problem solved... Thanks for the help.
"ma********@yahoo.com" <Ma********@yahoo.comwrote in message
news:Lt*******************@newssvr27.news.prodigy. net...
Thanks for the responses...

This is what I got using a DropDownList and a Button.

Dim parentfolder As String = "recipes"
Dim myDir As New DirectoryInfo(Server.MapPath(parentfolder))
Me.DDLFileNames.DataSource = myDir.GetFiles("*.doc")
Me.DDLFileNames.DataBind()
Session("FilePath") = myDir.ToString

**Click the download button and...
Session("FileName") = Me.DDLFileNames.SelectedItem.ToString
Response.Redirect("FileDownload.aspx")

**page load in FileDownload.aspx
Dim filename As String = DirectCast(Session("FileName"), String)
Dim filepath As String = DirectCast(Session("FilePath"), String)
Dim fullpath As String = filepath + "\" + filename
Response.Clear()
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", _
"attachment; filename=""" & filename & """")
Response.Flush()
Response.WriteFile(fullpath)
Session.Abandon()

This works great running at home but when I upload it to my server the
file(aword.doc) gets downloaded and it is empty. Any ideas why that is?
Thanks again.
"Laurent Bugnion" <ga*********@bluewin.chwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>Hi,

Shahzad Godil wrote:
>>You can use FileSystemObject like this.

<%
Set objFSO=Server.CreateObject("Scripting.filesystemob ject")
Set objFold=objFSO.GetFolder("E:\admin\uploads")
Set objfiles=objFold.files
%>
and then generating my drop down using

<select name="productThumb" id="productThumb">
<option><%For Each objFile in objFolder.files
objFile.Name
Next
%></optio

Shahzad Godil

Karachi-Pakistan.

Are you seriously proposing using the FileSystemObject in an ASP.NET
environment? That's sub-optimal to say the least

To the OP: You get a list of files in a folder using the
System.IO.DirectoryInfo class.

For example:

DirectoryInfo dir = new DirectoryInfo( "c:\\temp" );
if ( dir.Exists )
{
FileInfo[] filesInDir = dir.GetFiles();
}

http://msdn2.microsoft.com/en-us/lib...ctoryinfo.aspx

HTH,
Laurent

>>>

"ma********@yahoo.com" <Ma********@yahoo.comwrote in message
news:ev*****************@newssvr27.news.prodigy. net...
I'm using .net 1.1 trying to get a list of files in folder on the
server. The user would select the file they want to download from a
DropDownList. Can someone tell me how this should be done? I can't
find the right class or object to use. Is it the File class or the
FolderBrowser? Stuck like Chuck!!! Any suggestions welcome. Thanks.

--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch


Oct 20 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ken | last post by:
I currently have a set of documents in a directory that i need to list in a html table. Is there any way to generate the table with the documents listed instead of having to update the table...
1
by: John | last post by:
Hi, we have the following problem: in our application v1.0 we have static html pages (+ some javascript). With a CMS (a Content Management System) some "mortal" people can add or expand the...
5
by: nospam | last post by:
Hi there, I'm using VBScript to display a list of the ten most recently updated pages on my web site. Right now, the script lists the filenames and the date modified in a given directory. ...
6
by: (PeteCresswell) | last post by:
User wants to go this route instead of storing pointers in the DB and the documents outside. Only time I tried it was with only MS Word docs - and that was a loooong time ago - and it seemed to...
0
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
1
by: shank | last post by:
I borrowed the below code from http://www.brainjar.com/asp/dirlist/ and cannot get it to read my folder files. I don't get any errors or any output to screen. I have the below folder permissions...
6
by: kimiraikkonen | last post by:
Hello, I have a listbox and folder browser control. I need to display all .mp3 files' pathes into listbox. It was Ok with openfiledialog but how can list all .mp3 extension- having files into...
7
by: SV | last post by:
I am using ASP.Net / VB.Net v 2005. I want to add text recognition to one of the text box of suburb in my form. What I want to do is when user type any character in that text box, one dynamic list...
0
AmberJain
by: AmberJain | last post by:
Windows Autorun FAQs: List of autostart locations Linked from the Original article- "Windows Autorun FAQs: Description". Que: Can you list all the autostart locations for windows? Ans: Here is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.