473,666 Members | 2,188 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5249

You can use FileSystemObjec t like this.

<%
Set objFSO=Server.C reateObject("Sc ripting.filesys temobject")
Set objFold=objFSO. GetFolder("E:\a dmin\uploads")
Set objfiles=objFol d.files
%>
and then generating my drop down using

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

Shahzad Godil

Karachi-Pakistan.
"ma********@yah oo.com" <Ma********@yah oo.comwrote in message
news:ev******** *********@newss vr27.news.prodi gy.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.

Oct 17 '06 #2
Hi,

Shahzad Godil wrote:
You can use FileSystemObjec t like this.

<%
Set objFSO=Server.C reateObject("Sc ripting.filesys temobject")
Set objFold=objFSO. GetFolder("E:\a dmin\uploads")
Set objfiles=objFol d.files
%>
and then generating my drop down using

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

Shahzad Godil

Karachi-Pakistan.
Are you seriously proposing using the FileSystemObjec t 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.Direc toryInfo 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********@yah oo.com" <Ma********@yah oo.comwrote in message
news:ev******** *********@newss vr27.news.prodi gy.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 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(S erver.MapPath(p arentfolder))
Me.DDLFileNames .DataSource = myDir.GetFiles( "*.doc")
Me.DDLFileNames .DataBind()
Session("FilePa th") = myDir.ToString

**Click the download button and...
Session("FileNa me") = Me.DDLFileNames .SelectedItem.T oString
Response.Redire ct("FileDownloa d.aspx")

**page load in FileDownload.as px
Dim filename As String = DirectCast(Sess ion("FileName") , String)
Dim filepath As String = DirectCast(Sess ion("FilePath") , String)
Dim fullpath As String = filepath + "\" + filename
Response.Clear( )
Response.Conten tType = "applicatio n/octet-stream"
Response.AddHea der("Content-Disposition", _
"attachment ; filename=""" & filename & """")
Response.Flush( )
Response.WriteF ile(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*********@bl uewin.chwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
Hi,

Shahzad Godil wrote:
>You can use FileSystemObjec t like this.

<%
Set objFSO=Server.C reateObject("Sc ripting.filesys temobject")
Set objFold=objFSO. GetFolder("E:\a dmin\uploads")
Set objfiles=objFol d.files
%>
and then generating my drop down using

<select name="productTh umb" id="productThum b">
<option><%Fo r Each objFile in objFolder.files
objFile.Name
Next
%></optio

Shahzad Godil

Karachi-Pakistan.

Are you seriously proposing using the FileSystemObjec t 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.Direc toryInfo 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********@ya hoo.com" <Ma********@yah oo.comwrote in message
news:ev******* **********@news svr27.news.prod igy.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
DropDownLis t. 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********@yah oo.com" <Ma********@yah oo.comwrote in message
news:Lt******** ***********@new ssvr27.news.pro digy.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(S erver.MapPath(p arentfolder))
Me.DDLFileNames .DataSource = myDir.GetFiles( "*.doc")
Me.DDLFileNames .DataBind()
Session("FilePa th") = myDir.ToString

**Click the download button and...
Session("FileNa me") = Me.DDLFileNames .SelectedItem.T oString
Response.Redire ct("FileDownloa d.aspx")

**page load in FileDownload.as px
Dim filename As String = DirectCast(Sess ion("FileName") , String)
Dim filepath As String = DirectCast(Sess ion("FilePath") , String)
Dim fullpath As String = filepath + "\" + filename
Response.Clear( )
Response.Conten tType = "applicatio n/octet-stream"
Response.AddHea der("Content-Disposition", _
"attachment ; filename=""" & filename & """")
Response.Flush( )
Response.WriteF ile(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*********@bl uewin.chwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
>Hi,

Shahzad Godil wrote:
>>You can use FileSystemObjec t like this.

<%
Set objFSO=Server.C reateObject("Sc ripting.filesys temobject")
Set objFold=objFSO. GetFolder("E:\a dmin\uploads")
Set objfiles=objFol d.files
%>
and then generating my drop down using

<select name="productTh umb" id="productThum b">
<option><%F or Each objFile in objFolder.files
objFile.Nam e
Next
%></optio

Shahzad Godil

Karachi-Pakistan.

Are you seriously proposing using the FileSystemObjec t 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.Dire ctoryInfo class.

For example:

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

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

HTH,
Laurent

>>>

"ma********@y ahoo.com" <Ma********@yah oo.comwrote in message
news:ev****** ***********@new ssvr27.news.pro digy.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
FolderBrowse r? 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
2760
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 manually everytime a new document is added to the list. Thanks Ken
1
2908
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 available images for the start site. The site loads randomly an image or a Flash animation (if the flash plugin is present) through a javascript and each time the start site loades and displays only 1 different picture. At the moment the name of...
5
2451
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. What I want to know is if there is any way to extract the page title and display that instead of the file name? Can I use .asp and VBscript to "delve" into the file and extract the title?
6
3191
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 me like there were performance issues at the time. How about the different types? The MS docs I would expect Access to differentiate and handle appropriately (i.e. .DOC and .XLS).. but how about ..PDF? and can I stash a .TXT document in the...
0
2906
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 strDataValueField; string strDataTextField; public CreateEditItemTemplateDDL(string DDLName,string DataValueField,string
1
5553
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 set to browse. Without using the below page, I can browse the files. What did I miss? thanks! <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> <% set fs = CreateObject("Scripting.FileSystemObject") set folder = fs.GetFolder("c:\inetpub\wwwroot\bs\aa\")...
6
3151
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 my listbox using folder browser control. A sample code would be great.
7
1955
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 appear under that text box having all suburb name start with that character. How do I achieve that? Any hints…… Any help will be appreciated. Thanks,
0
30208
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 a comprehensive list of all autostart locations for Windows OSes: NOTE : These are some abbreviations used in this list. Please note them carefully: HKCU = HKEY_CURRENT_USER HKLM = HKEY_LOCAL_MACHINE
0
8454
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8362
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8878
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8785
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8644
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6200
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5671
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2776
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2012
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.