简体   繁体   中英

ASPxUploadControl - get uploaded file on the server-side

I am using several ASPxUploadControl s in my page. I am successfully getting the uploaded files using FileUploadComplete event's e.UploadedFile argument and saving them.

But I want to be able to access (and save) them after saving my main entity. The reason is that I need to save them in a folder the name of which will be my entity's ID.

Is there a way I can do something like myUploadControl.TheFileItIsCarrying where ever I want in my C# code?

I tried myUploadControl.UploadedFiles[0] , but it will return a file with no content.

PS1: I thought of saving them in a temporary folder and then moving to the right folder. But in that case, I will not know each file is whose if several clients upload simultaneously.

PS2: The scenario is like saving a number of Party entities along with scanned copies of their identity documents, Resumes, etc.

If you are actually saving the uploaded file to the server, you can save the upload file first, then you should be able to do whatever you want with the file, I don't know if you are actually saving it or not but that may be the problem that is occurring.

 If FileUpload1.HasFile Then
        Try
            Dim realPhysicalPath As String = Path.Combine(Server.MapPath("~\Files\"), FileUpload1.PostedFile.FileName)
            FileUpload1.PostedFile.SaveAs(realPhysicalPath)

            Label1.Text = "File name: " & _
               FileUpload1.PostedFile.FileName & "<br>" & _
               "File Size: " & _
               FileUpload1.PostedFile.ContentLength & " kb<br>" & _
               "Content type: " & _
               FileUpload1.PostedFile.ContentType
        Catch ex As Exception
            Label1.Text = "ERROR: " & ex.Message.ToString()
        End Try
    Else
        Label1.Text = "You have not specified a file."
    End If

Then you can pull that specific file from the server, my example is assigning all the saved uploaded files to a GridView

 Dim filePaths() As String = Directory.GetFiles(Server.MapPath("~/Files/"))
        Dim files As List(Of ListItem) = New List(Of ListItem)
        For Each filePath As String In filePaths

            files.Add(New ListItem(Path.GetFileName(filePath)))
        Next
        Dim hplnk As New HyperLinkField()

        hplnk.DataTextField = "test"
        hplnk.Text = "test"
        hplnk.HeaderText = "yourHeaderTextValue"

        GridView1.DataSource = files



        GridView1.DataBind()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM