Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6994493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:53:59+00:00 2026-05-27T19:53:59+00:00

how do I convert an httppostedfile to an htmlinputfile? I’m working with an old

  • 0

how do I convert an httppostedfile to an htmlinputfile? I’m working with an old mess of an app and so far have been able to refactor it so it makes a bit of sense, but this particular mess is too tangled to be worth the effort :S.

Thanks, as usual, for the help

relevant code:

collection:

Imports System.IO
Imports System.Web.UI.HtmlControls
Public Class ArchivosCollection
    Inherits CollectionBase

    Default Public Property Item(ByVal index As Integer) As HtmlInputFile
        Get
            Return MyBase.List(index)
        End Get
        Set(ByVal Value As HtmlInputFile)
            MyBase.List(index) = Value
        End Set
    End Property

    Public Function Add(ByVal oArchivo As HtmlInputFile) As Integer
        Return MyBase.List.Add(oArchivo)
    End Function

    Public Function getDataSource() As DataTable
        Dim dt As New DataTable
        Dim oArchivo As HtmlInputFile
        Dim fila As DataRow
        Dim orden As Integer = 0
        dt.Columns.Add("documento", GetType(System.String))
        dt.Columns.Add("tipo", GetType(System.String))
        For Each oArchivo In list
            If Not oArchivo.Disabled Then
                fila = dt.NewRow()
                fila("documento") = Trim(Path.GetFileName(oArchivo.PostedFile.FileName))
                fila("tipo") = Trim(oArchivo.PostedFile.ContentType)
                dt.Rows.Add(fila)
            End If
        Next
        Return dt
    End Function

    Public Function ExisteArchivo(ByVal Nombre As String) As Boolean
        For Each oArchivo As HtmlInputFile In list
            If Not oArchivo.Disabled Then
                If Path.GetFileName(oArchivo.PostedFile.FileName) = Nombre Then
                    Return True
                End If
            End If
        Next
        Return False
    End Function

    Public Function EliminarArchivo(ByVal Nombre As String) As Boolean
        For Each oArchivo As HtmlInputFile In list
            If Not oArchivo.Disabled Then
                If Path.GetFileName(oArchivo.PostedFile.FileName) = Nombre Then
                    oArchivo.Disabled = True
                    Return True
                End If
            End If
        Next
    End Function
End Class

old code:

Private Sub btnAgregarDocumento_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAgregarDocumento.Click
    Try
        If Not (Me.fleDocumento.PostedFile Is Nothing) Then
            If Trim(Me.fleDocumento.PostedFile.FileName) = "" Then
                Throw New Exception(rm.GetString("errorDebeEscogerUnArchivo"))
            End If
            If Not Servicios.isValidUploadType(Me.fleDocumento.PostedFile.FileName, ConfigurationManager.AppSettings("Filtros Upload")) Then
                Throw New Exception(rm.GetString("errorExtensionNovalida"))
            End If
            Dim oArchivosOT As ArchivosCollection
            If Session("oArchivosOT") Is Nothing Then
                oArchivosOT = New ArchivosCollection
            Else
                oArchivosOT = Session("oArchivosOT")
            End If
            If oArchivosOT.ExisteArchivo(Path.GetFileName(Me.fleDocumento.PostedFile.FileName)) Then
                Throw New Exception(rm.GetString("errorArchivoYaExiste"))
            End If
            oArchivosOT.Add(Me.fleDocumento)
            Me.dgDocumentos.DataSource = oArchivosOT.getDataSource()
            Me.dgDocumentos.DataBind()
            Session("oArchivosOT") = oArchivosOT
            If Request.QueryString("desde") = "proy" Then
                ClientScript.RegisterStartupScript(Page.GetType, "msg", "<script>window.opener.document.Form1.refGridDocs.click();</script>")
            End If
        Else
            Throw New Exception(rm.GetString("errorDebeEscogerUnArchivo"))
        End If
    Catch exc As Exception
        ClientScript.RegisterStartupScript(Page.GetType, "msg", Servicios.MsgBox(exc.Message))
    End Try
End Sub

new code (partial):

Dim archivos As HttpFileCollection = Request.Files
            Dim colArchivos As ArchivosCollection = IIf(Session("oArchivosOT") Is Nothing, New ArchivosCollection(), Session("oArchivosOT"))
            Dim i
            For i = 0 To archivos.Count
                colArchivos.Add(DirectCast(archivos(i), HtmlInputFile))
            Next

            Session("oArchivosOT") = colArchivos
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:54:00+00:00Added an answer on May 27, 2026 at 7:54 pm

    The PostedFile property of the HtmlInputFile object is a HttpPostedFile object – you can simply access it for each HtmlInputFile.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Convert iPad application to iPhone- Universal app. I already have one iPad application, now
The Convert class has been in existence since .NET 1.0. The IConvertible interface has
my convert code is all i have, but it converts a string to sha-1
I have created one user control and need to convert that user control into
While googling how to convert a BIT (YESNO) column in an access database to
I'm trying to convert a timestamp string to Date in PHP. I have following
Convert angle in degrees to a point How could I convert an angle (in
convert this: $300 to this : 300 can't do it with intval() or (int)
select convert(varbinary(8), 1) in MS SQL Server produces output : 0x00000001 On assigning the
AIM : Convert a resultset to XML and assign the result to a variable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.