Link to home
Start Free TrialLog in
Avatar of mishelper
mishelper

asked on

ASP.NET Access to folders and files at client side

I have 2 questions here:

1. Is it possible to write a web application, while user specify a file / a directory, and the web application can loop folder the directory and list out all files within that folder?
2. Assume I get point 1 acheived, is it possible for me to upload all files in that folder to server?

I have the following code. It works fine at my computer (I hosted it here), but access denied when the actual user tested it.
TASK 1.
===========================================================================
        Dim ds() As Integer
        Dim dirInfo As DirectoryInfo
        Dim files() As FileInfo
        Dim i As Integer
        Dim myFile As String
 
        If (fulFileField.HasFile) Then
            Try
                myFile = fulFileField.PostedFile.FileName
                myDir = System.IO.Path.GetDirectoryName(myFile)
                ViewState("myFile") = myDir
                If (optSingleFile.Checked) Then
                    ReDim ds(0)
                    gvwUploadFiles.DataSource = ds
                    gvwUploadFiles.DataBind()
                    DirectCast(gvwUploadFiles.Rows(0).FindControl("HLinkFile"), Label).Text = System.IO.Path.GetFileName(myFile)
                ElseIf (optMultiFile.Checked) Then
                    dirInfo = New DirectoryInfo(myDir)
                    files = dirInfo.GetFiles
                    ReDim ds(files.Length - 1)
                    gvwUploadFiles.DataSource = ds
                    gvwUploadFiles.DataBind()
                    For i = 0 To files.Length - 1
                        myFile = files(i).FullName
                        DirectCast(gvwUploadFiles.Rows(i).FindControl("HLinkFile"), Label).Text = System.IO.Path.GetFileName(myFile)
                        'DirectCast(gvwUploadFiles.Rows(i).FindControl("HLinkFile"), Label).Text = "<a href=""" & myFile & """>" & System.IO.Path.GetFileName(myFile) & "</a>"
                        'DirectCast(gvwUploadFiles.Rows(i).FindControl("HLinkFile"), HyperLink).NavigateUrl = myFile 'Server.UrlDecode(myFile)
                    Next i
                End If
                cmdDisplay.Visible = False
                cmdUpload.Visible = True
                span1.InnerHtml = "Tag the files."
            Catch ex As Exception
                'span1.InnerHtml = "Error: " & ex.ToString
            End Try
        Else
            span1.InnerHtml = "Select a file using the browse button."
            Exit Sub
        End If
===========================================================================
TASK 2
===========================================================================
        Dim i As Integer
        Dim myFile As String
        Try
            For i = 0 To gvwUploadFiles.Rows.Count - 1
                myFile = DirectCast(gvwUploadFiles.Rows(i).FindControl("HLinkFile"), Label).Text
                File.Copy(ViewState("myFile") & "\" & myFile, "C:\UploadedUserFiles\" & myFile, True)
            Next i
 
            span1.InnerHtml = "File upload successful."
        Catch ex As Exception
            span1.InnerHtml = "File upload FAILED."
        End Try
===========================================================================

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
there are some components which lets user select multiple files (one by one) and upload (one by one again), like telerik upload control...
look at DeVIL

http://openil.sourceforge.net/download.php

a free image library which you can use it to get all image properties...
please ignore previous post (25522092)
Avatar of mishelper
mishelper

ASKER

Your comments are helpful. I thought that is a matter of impersonation or web.config setting.

I will probably use FileUpload control, and let users to select files one by one.