Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Getting List of Files in a Folder

Reply
Thread Tools

Getting List of Files in a Folder

 
 
chuckdfoster
Guest
Posts: n/a
 
      02-07-2005
I am not sure if this is even possible, but I figured I'd ask some experts.
How would I use an ASP.NET page to get a listing of all of the files that
are in a folder. I am working on a page that can show a group of users if
their reports are in a folder (kind of like a report distribution page). If
that is possible then how could I put a link on the page to that file so the
user could open it.

Thanks!

--
Chuck Foster
Programmer Analyst
Eclipsys Corporation - St. Vincent Health System


 
Reply With Quote
 
 
 
 
Juan T. Llibre
Guest
Posts: n/a
 
      02-07-2005
DirList.aspx
=========
<script language="vb" runat="server">
Sub Page_Load()
Dim StoreFile As System.IO.Directory
Dim Files As String()
Dim File As String
Files = StoreFile.GetFiles("drive:\directory\path\", "*")
For Each File In Files
Response.Write(File & "<br>")
Next
End Sub
</script>

<html>
<head><title>File List</title></head>
<body>

</body>
</html>
---------



Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Espaņol
=====================

"chuckdfoster" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>I am not sure if this is even possible, but I figured I'd ask some experts.
> How would I use an ASP.NET page to get a listing of all of the files that
> are in a folder. I am working on a page that can show a group of users if
> their reports are in a folder (kind of like a report distribution page).
> If
> that is possible then how could I put a link on the page to that file so
> the
> user could open it.
>
> Thanks!
>
> --
> Chuck Foster
> Programmer Analyst
> Eclipsys Corporation - St. Vincent Health System
>
>



 
Reply With Quote
 
 
 
 
Mark Rae
Guest
Posts: n/a
 
      02-07-2005
"chuckdfoster" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...

>I am not sure if this is even possible, but I figured I'd ask some experts.
> How would I use an ASP.NET page to get a listing of all of the files that
> are in a folder. I am working on a page that can show a group of users if
> their reports are in a folder (kind of like a report distribution page).
> If
> that is possible then how could I put a link on the page to that file so
> the
> user could open it.


No problem at all. Take a look at the System.IO namespace, instantiate a
Directory object and then call its GetFiles method e.g.

using System.IO;

string[] astrFiles = Directory.GetFiles(<directory name goes here>, "*.*");
foreach (string strFile in astrFiles)
{
// write out a hyperlink to the file which the users can click
}

Make sure that the account that ASP.NET is running under needs to be able to
"see" the directory and have sufficient permissions on it to get a listing
of its files.


 
Reply With Quote
 
Karl Seguin
Guest
Posts: n/a
 
      02-07-2005
Chuck:

check out System.IO.Directory.GetDirectories and
System.IO.Directory.GetFiles

for each file as string in System.IO.Directory.GetFiles("c:\repository\")

next

If there's a folder tree (ie, you need to recurse), you'll need a recursive
function. How to put a link to the file depends on whether the file exists
in the web directory or in some other folder. If it's in the web
directory, you can simply link to it. Otherwise look at the
REsponse.WriteFile method.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


"chuckdfoster" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> I am not sure if this is even possible, but I figured I'd ask some

experts.
> How would I use an ASP.NET page to get a listing of all of the files that
> are in a folder. I am working on a page that can show a group of users if
> their reports are in a folder (kind of like a report distribution page).

If
> that is possible then how could I put a link on the page to that file so

the
> user could open it.
>
> Thanks!
>
> --
> Chuck Foster
> Programmer Analyst
> Eclipsys Corporation - St. Vincent Health System
>
>



 
Reply With Quote
 
Karl Seguin
Guest
Posts: n/a
 
      02-07-2005
Juan:
Your use of a shared field like that struck me odd. System.IO.Directory
can't be created (constructor is private, class is sealed and all members
are static) so, in my opinion you should always use System.IO.Directory.XXX
instead of creating a field and then doing someField.XXX. In VB.Net you can
do:

Dim x as System.IO.Directory

but in C# you can't do the same, ie:

System.IO.Directory x = System.IO.Directory;

Might just be a personal preference of mine, all I could quickly dig up was
this discussion:
http://dotnetjunkies.com/WebLog/gran...3/02/8249.aspx


Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/


"Juan T. Llibre" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> DirList.aspx
> =========
> <script language="vb" runat="server">
> Sub Page_Load()
> Dim StoreFile As System.IO.Directory
> Dim Files As String()
> Dim File As String
> Files = StoreFile.GetFiles("drive:\directory\path\", "*")
> For Each File In Files
> Response.Write(File & "<br>")
> Next
> End Sub
> </script>
>
> <html>
> <head><title>File List</title></head>
> <body>
>
> </body>
> </html>
> ---------
>
>
>
> Juan T. Llibre
> ASP.NET MVP
> http://asp.net.do/foros/
> Foros de ASP.NET en Espaņol
> =====================
>
> "chuckdfoster" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> >I am not sure if this is even possible, but I figured I'd ask some

experts.
> > How would I use an ASP.NET page to get a listing of all of the files

that
> > are in a folder. I am working on a page that can show a group of users

if
> > their reports are in a folder (kind of like a report distribution page).
> > If
> > that is possible then how could I put a link on the page to that file so
> > the
> > user could open it.
> >
> > Thanks!
> >
> > --
> > Chuck Foster
> > Programmer Analyst
> > Eclipsys Corporation - St. Vincent Health System
> >
> >

>
>



 
Reply With Quote
 
Juan T. Llibre
Guest
Posts: n/a
 
      02-08-2005
Looks like we found something which can be
done in VB.NET which can't be done in C#.



No errors, no warnings. It just works.




Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Espaņol
=====================

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:(E-Mail Removed)...
> Juan:
> Your use of a shared field like that struck me odd. System.IO.Directory
> can't be created (constructor is private, class is sealed and all members
> are static) so, in my opinion you should always use
> System.IO.Directory.XXX
> instead of creating a field and then doing someField.XXX. In VB.Net you
> can
> do:
>
> Dim x as System.IO.Directory
>
> but in C# you can't do the same, ie:
>
> System.IO.Directory x = System.IO.Directory;
>
> Might just be a personal preference of mine, all I could quickly dig up
> was
> this discussion:
> http://dotnetjunkies.com/WebLog/gran...3/02/8249.aspx
>
>
> Karl
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/
>
>
> "Juan T. Llibre" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> DirList.aspx
>> =========
>> <script language="vb" runat="server">
>> Sub Page_Load()
>> Dim StoreFile As System.IO.Directory
>> Dim Files As String()
>> Dim File As String
>> Files = StoreFile.GetFiles("drive:\directory\path\", "*")
>> For Each File In Files
>> Response.Write(File & "<br>")
>> Next
>> End Sub
>> </script>
>>
>> <html>
>> <head><title>File List</title></head>
>> <body>
>>
>> </body>
>> </html>
>> ---------
>>
>>
>>
>> Juan T. Llibre
>> ASP.NET MVP
>> http://asp.net.do/foros/
>> Foros de ASP.NET en Espaņol
>> =====================
>>
>> "chuckdfoster" <(E-Mail Removed)> wrote in message
>> news:%(E-Mail Removed)...
>> >I am not sure if this is even possible, but I figured I'd ask some

> experts.
>> > How would I use an ASP.NET page to get a listing of all of the files

> that
>> > are in a folder. I am working on a page that can show a group of users

> if
>> > their reports are in a folder (kind of like a report distribution
>> > page).
>> > If
>> > that is possible then how could I put a link on the page to that file
>> > so
>> > the
>> > user could open it.
>> >
>> > Thanks!
>> >
>> > --
>> > Chuck Foster
>> > Programmer Analyst
>> > Eclipsys Corporation - St. Vincent Health System
>> >
>> >

>>
>>

>
>



 
Reply With Quote
 
Mark Rae
Guest
Posts: n/a
 
      02-08-2005
"Juan T. Llibre" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...

> Looks like we found something which can be
> done in VB.NET which can't be done in C#.
>
>
>
> No errors, no warnings. It just works.


Wow!


 
Reply With Quote
 
chuckdfoster
Guest
Posts: n/a
 
      02-08-2005
Thanks to everyone! This is all great help.
Chuck
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:(E-Mail Removed)...
> Chuck:
>
> check out System.IO.Directory.GetDirectories and
> System.IO.Directory.GetFiles
>
> for each file as string in System.IO.Directory.GetFiles("c:\repository\")
>
> next
>
> If there's a folder tree (ie, you need to recurse), you'll need a

recursive
> function. How to put a link to the file depends on whether the file

exists
> in the web directory or in some other folder. If it's in the web
> directory, you can simply link to it. Otherwise look at the
> REsponse.WriteFile method.
>
> Karl
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/
>
>
> "chuckdfoster" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > I am not sure if this is even possible, but I figured I'd ask some

> experts.
> > How would I use an ASP.NET page to get a listing of all of the files

that
> > are in a folder. I am working on a page that can show a group of users

if
> > their reports are in a folder (kind of like a report distribution page).

> If
> > that is possible then how could I put a link on the page to that file so

> the
> > user could open it.
> >
> > Thanks!
> >
> > --
> > Chuck Foster
> > Programmer Analyst
> > Eclipsys Corporation - St. Vincent Health System
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
32bit Program installed to the Program Files folder and not the PFx86 folder murdock69u@gmail.com Windows 64bit 1 04-30-2009 01:30 PM
TRying to import files from my folder not pythons lib folder tedpottel@gmail.com Python 7 09-25-2007 02:36 AM
unable to create the folder "new folder: no new files Cindy Stuart Computer Support 5 06-03-2007 07:32 AM
How do you get a list of files from server folder to display on in a list control maglev_now@yahoo.com ASP .Net 4 10-20-2006 12:39 PM
Can't copy Outlook Ex files in folder to Windows folder? Paul - xxx Computer Support 2 08-20-2003 03:06 AM



Advertisments