Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4.5.1 > ASP.NET 4.5.1 General Discussion
|
ASP.NET 4.5.1 General Discussion For ASP.NET 4.5.1 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4.5.1 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 12th, 2017, 06:25 PM
Registered User
 
Join Date: Feb 2017
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default HttpFileCollectionBase Cannot get uploads

I'm using request.files as HttpFileCollectionBase and passing them into the Class File using a public variable. The count property is 1 even no file is upload so I don't know how to if file upload before call the construct method.

I also cannot iterate the collection. The P_ variables are class private passed in from the public property assignments.

The construct method:


Code:
    
    Private p_filesToAttach As HttpFileCollectionBase

    Public Property FilesToAttach() As HttpFileCollectionBase
        Get
            Return p_filesToAttach
        End Get
        Set(ByVal value As HttpFileCollectionBase)
            p_filesToAttach = value
        End Set
    End Property

Public Sub ConstructUpload()
        ' Get full path to the attachments folder
        Dim FolderPath As String = Current.Server.MapPath(p_attachmentFolder) + "\"
        Dim strFileName As String = ""
        Dim httpFiles = p_filesToAttach
        Dim i = p_filesToAttach.Count

        Try
            For Each upfile In httpFiles
                'Dim upfile As HttpPostedFileBase =
                If upfile.ContentLength > 0 Then
                    Current.Response.Write("this is it")
                    Current.Response.End()
                End If

                strFileName = Path.GetFileName(upfile.FileName)
                'verify file exists

                If Not String.IsNullOrEmpty(strFileName) Then
                    'set file paths
                    Dim filePath As String = FolderPath + GetFilePath(strFileName)
                    If Not (upfile) Is Nothing Then
                        Current.Response.Write(p_filesToAttach.Count)
                        Current.Response.End()
                    End If

                    'check file size
                    If upfile.ContentLength > (250 * 1000) Then
                        Throw New WebException("Upload file:" & strFileName & " exceeds the allowed size of: " & (p_attachmentMaxLength * 1000) & " kilobytes.")
                    Else
                        'Create the directory if it does not exist.
                        If (Not Directory.Exists(FolderPath)) Then
                            If CheckFolderPermissions(FolderPath) Then
                                Directory.CreateDirectory(FolderPath)
                            Else
                                Throw New WebException("You don't have permission to attach the file: " & strFileName & ".")
                            End If
                        End If
                        ' Delete existing files with same name before uploading new.
                        If File.Exists(filePath) Then
                            If CheckFolderPermissions(FolderPath) Then
                                File.Delete(filePath)
                            Else
                                Throw New WebException("You don't have permission to attach the file: " & strFileName & ".")
                            End If
                        End If
                        ' Call UploadAttachments to upload the file.
                        UploadFiles(upfile, upfile.FileName, FolderPath)
                    End If
                Else
                    Throw New WebException("Upload file cannot be found.")
                End If
            Next
        Catch e As WebException
            ErrorCodes.Add(e)
        End Try

    End Sub ' ConstructUpload
 
Old August 27th, 2017, 01:57 PM
Registered User
 
Join Date: Aug 2017
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Better is to check with javascript to find out if user has selected any file before the submit the form or postback is initiated. This is also more faster in client computer to check for file selected than the server when the postback is invoked.
 
Old August 30th, 2017, 03:39 PM
Registered User
 
Join Date: Feb 2017
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I went a different way. You can find my solution here: https://github.com/wwwebconcepts/RazorSmartMailer





Similar Threads
Thread Thread Starter Forum Replies Last Post
asp uploads red_fiesta Classic ASP Basics 0 October 17th, 2007 04:28 AM
File Uploads seananderson Classic ASP Basics 1 November 14th, 2006 12:29 PM
How to add more file uploads? fyp4135 C# 2005 3 November 8th, 2006 11:55 PM
Multiple file uploads felixDa BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 2 April 17th, 2006 10:37 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.