locked
An Upload file Class RRS feed

  • Question

  • User1589032278 posted

    I had developed a class for uploading files.....

     

    1    Public Class FileUploader
    2    
    3        Public Sub UploadFile(ByVal fileUploader As FileUpload, ByVal fileName As String, ByVal path As String, Optional ByVal maxSize As Integer = 9437184)
    4    
    5            If fileUploader.HasFile = True AndAlso fileUploader.PostedFile IsNot Nothing Then
    6    
    7                ' equal 9 mb by default
    8                Dim _fileExt As String = System.IO.Path.GetExtension(fileUploader.FileName)
    9                'If (_fileExt.ToLower() <> ".gif") And (_fileExt.ToLower() <> ".jpeg") And (_fileExt.ToLower() & ".jpg") Then
    10               If fileUploader.PostedFile.ContentLength <= maxSize Then
    11   
    12                   Dim AdsFile As String = fileName + _fileExt
    13                   fileUploader.SaveAs(path & AdsFile)
    14                   MsgBox("success")
    15   
    16               Else
    17                   fileUploader.Focus()
    18                   'ClientScript.RegisterStartupScript(Type.[GetType]("System.String"), "messagebox", "<script type=""text/javascript"">alert('Max file size is 10 m.b');</script>")
    19               End If
    20   
    21               'Else
    22               'fileUploader.Focus()
    23               ' ClientScript.RegisterStartupScript(Type.[GetType]("System.String"), "messagebox", "<script type=""text/javascript"">alert('Only GIF or JPEGare allowed');</script>")
    24               'End If
    25           Else
    26               fileUploader.Focus()
    27               '    nErrCode = -1
    28               'strError = "There is No Posted File"
    29           End If
    30   
    31       End Sub
    32   
    33   End Class
    

     

    Hope it helpful for you and  to see your feedback and comments...

    Wednesday, December 3, 2008 6:01 PM

All replies

  • User-319574463 posted

     A good start, however the following would be helpful:

    • An explicit copyright notice using one like the LGPL - which explicitly allows copying without copying
    • XML documentation of the Function
    Monday, December 8, 2008 10:19 AM
  • User1589032278 posted

    thanks TATWORTH  for your notes

    Monday, December 8, 2008 6:00 PM