Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ''' <summary>
- ''' Attach handler to Upload control. So a click on the control executes Javascript to invoke the wiseJ upload mechanism
- ''' </summary>
- ''' <param name="ctrl"></param>
- Public Sub AttachUploadInvokeToControl(ByVal ctrl As Control)
- Me.Upload1.CreateControl()
- ctrl.Eval(String.Format(vbCr & vbLf & "this.uploadButton = Wisej.Core.getComponent(""id_{0}"");" & vbCr & vbLf &
- " this.addListener(""execute"", function(e)" & vbCr & vbLf &
- " {{" & vbCr & vbLf & " this.uploadButton.upload();" & vbCr & vbLf &
- " }});", Me.Upload1.Handle))
- End Sub
- ''Event for upload progress. Update UI based on upload progress
- Private Sub Upload1_Progress(sender As Object, e As UploadProgressEventArgs) Handles Upload1.Progress
- Dim intLoaded As Integer = e.Loaded
- Dim intTotal As Integer = e.Total
- Dim sngPercent As Single = intLoaded / intTotal
- Dim strTotalPercent = String.Format("{0:0%}", sngPercent)
- If strTotalPercent <> "NaN" Then
- Me.lblTapForPhoto.Text = "Tap to add an optional photo. (" + strTotalPercent + ")"
- End If
- End Sub
- Private Sub Upload1_Uploaded(sender As Object, e As Wisej.Web.UploadedEventArgs) Handles Upload1.Uploaded
- LoadFile(e.Files)
- End Sub
- ''' <summary>
- ''' Loads an uploaded file into the picturebox, saves file on server temporarily
- ''' </summary>
- ''' <param name="files"></param>
- Private Sub LoadFile(files As HttpFileCollection)
- If files Is Nothing Then
- Return
- End If
- If files.Count = 0 Then
- 'If no file was uploaded, reset picturebox to nothing..
- Me.pbPicture.Image = Nothing
- Else
- 'If there is a file, set the picturebox to it
- Dim CIR As New CustomImageResizer(files(0).InputStream)
- Me.pbPicture.Image = CIR.CropImage(pbPicture.Width, pbPicture.Height)
- CIR.DisposeOriginalBMP()
- If Me.pbPicture.Image Is Nothing Then
- AlertBox.Show("Image file could not be decoded. Please try again", MessageBoxIcon.Error)
- lblTapForPhoto.Text = "Tap to add an optional photo."
- Me.pbPicture.ImageSource = "Resources/Images/noimage.png"
- boolImageSuccessfullyUploaded = False
- Exit Sub
- End If
- strImageTemporaryFileName = files(0).FileName
- 'Save image to server temporarily
- If files(0).ContentLength > 0 Then
- Dim temp As String = System.IO.Path.GetTempPath()
- Dim path__1 = System.IO.Path.Combine(temp, strImageTemporaryFileName)
- files(0).SaveAs(path__1)
- strImageTemporaryFileName = path__1
- End If
- 'Me.pbPicture.Image.Width'Perform any image resizing here
- boolImageSuccessfullyUploaded = True 'set success flag.
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement