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

Discussion in 'ASP .Net' started by maglev_now@yahoo.com, Oct 17, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. You can use FileSystemObject like this.

    <%
    Set objFSO=Server.CreateObject("Scripting.filesystemobject")
    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.


    "" <> wrote in message
    news:evXYg.18504$...
    > 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.
    >
    Shahzad Godil, Oct 17, 2006
    #2
    1. Advertising

  3. Re: How do you get a list of files from server folder to displayon in a list control

    Hi,

    Shahzad Godil wrote:
    > You can use FileSystemObject like this.
    >
    > <%
    > Set objFSO=Server.CreateObject("Scripting.filesystemobject")
    > 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/library/system.io.directoryinfo.aspx

    HTH,
    Laurent


    >
    >
    > "" <> wrote in message
    > news:evXYg.18504$...
    >> 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
    Laurent Bugnion, Oct 17, 2006
    #3
  4. Guest

    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" <> wrote in message
    news:%...
    > Hi,
    >
    > Shahzad Godil wrote:
    >> You can use FileSystemObject like this.
    >>
    >> <%
    >> Set objFSO=Server.CreateObject("Scripting.filesystemobject")
    >> 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/library/system.io.directoryinfo.aspx
    >
    > HTH,
    > Laurent
    >
    >
    >>
    >>
    >> "" <> wrote in message
    >> news:evXYg.18504$...
    >>> 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, 2006
    #4
  5. Guest

    Problem solved... Thanks for the help.
    "" <> wrote in message
    news:LtDZg.21093$...
    > 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" <> wrote in message
    > news:%...
    >> Hi,
    >>
    >> Shahzad Godil wrote:
    >>> You can use FileSystemObject like this.
    >>>
    >>> <%
    >>> Set objFSO=Server.CreateObject("Scripting.filesystemobject")
    >>> 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/library/system.io.directoryinfo.aspx
    >>
    >> HTH,
    >> Laurent
    >>
    >>
    >>>
    >>>
    >>> "" <> wrote in message
    >>> news:evXYg.18504$...
    >>>> 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, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. THY
    Replies:
    3
    Views:
    2,906
    Alvin Bruney
    Oct 16, 2003
  2. bala
    Replies:
    3
    Views:
    537
    Stefan Schulz
    Dec 18, 2004
  3. Replies:
    7
    Views:
    386
    Gabriel Genellina
    Sep 25, 2007
  4. George
    Replies:
    1
    Views:
    173
    Robert Klemme
    Sep 15, 2009
  5. nafogel
    Replies:
    1
    Views:
    80
    David Dorward
    Jul 31, 2006
Loading...

Share This Page