Änderungen Fileupload

This commit is contained in:
ja
2021-10-25 09:03:06 +02:00
parent 09db2934e6
commit f5e9e3928d
2 changed files with 57 additions and 17 deletions

View File

@@ -2,20 +2,14 @@
Partial Class login_CreateUser
Inherits System.Web.UI.Page
Protected Sub FileUpload_Mobile_Init(sender As Object, e As EventArgs)
Protected Sub Page_Load(sender As Object, e As EventArgs)
If Not User.Identity.IsAuthenticated Then
FormsAuthentication.RedirectToLoginPage()
End If
End Sub
Protected Sub FileUpload_Desktop_Init(sender As Object, e As EventArgs)
End Sub
Protected Sub LinkButton1_Click(sender As Object, e As EventArgs)
Dim validFileTypes As String() = {"bmp", "gif", "png", "jpg", "jpeg", "doc", "xls"}
Dim validFileTypes As String() = {"bmp", "gif", "png", "jpg", "jpeg"}
Dim ext As String = System.IO.Path.GetExtension(FileUpload_Mobile.PostedFile.FileName)
Dim isValidFile As Boolean = False
For i As Integer = 0 To validFileTypes.Length - 1
@@ -35,11 +29,13 @@ Partial Class login_CreateUser
End Sub
Protected Sub btn_Save_Changes_Click(sender As Object, e As EventArgs)
Dim validFileTypes As String() = {"bmp", "gif", "png", "jpg", "jpeg", "doc", "xls"}
Dim validFileTypes As String() = {"bmp", "gif", "png", "jpg", "jpeg"}
Dim ext As String = System.IO.Path.GetExtension(FileUpload_Desktop.PostedFile.FileName)
Dim isValidFile As Boolean = False
Dim pathtosave As String = String.Empty
For i As Integer = 0 To validFileTypes.Length - 1
If ext = "." & validFileTypes(i) Then
pathtosave = "../images/users/" + Me.Page.User.Identity.Name + "/ImageProf"
isValidFile = True
Exit For
End If
@@ -49,6 +45,7 @@ Partial Class login_CreateUser
lbl_message_desktop.Text = "Invalid File. Please upload a File with extension " &
String.Join(",", validFileTypes)
Else
FileUpload_Desktop.PostedFile.SaveAs(pathtosave + "/" + Date.Now.ToShortDateString + "." + System.IO.Path.GetExtension(FileUpload_Desktop.PostedFile.FileName))
lbl_message_desktop.ForeColor = System.Drawing.Color.Green
lbl_message_desktop.Text = "File uploaded successfully."
End If