Fileupload Handling on DetailsView_RowInserting

  • Thread starter Christian Schlemmer
  • Start date
C

Christian Schlemmer

If my code will run into the filesize-limit condition, the INSERT-statement
will be executed.

is there a way to avoid that?



Protected Sub DetailsView1_RowInserting(ByVal sender As Object, ByVal e
As DetailsViewInsertEventArgs)
Dim FileUpload As FileUpload = DetailsView1.FindControl("Bild")
If InStr(UCase(FileUpload.FileName), ".JPG") = 0 Then
txtInfo.InnerHtml = "Bitte whlen Sie ein Bild im Format .JPG"
Return
End If
If FileUpload.PostedFile.ContentLength > 1000000 Then
txtInfo.InnerHtml = "Das Limit fr die Dateigrsse betrgt 1 MB"
Return
End If
If FileUpload.HasFile = True Then
'write original
Dim strFileName As String = FileUpload.FileName.ToString
Dim serverPath As String = Server.MapPath("Upload/")
Dim uploadPath As String = "../Upload/"
Dim fileToUpload As String =
FileUpload.PostedFile.FileName.ToString
Dim fileExtension As String =
System.IO.Path.GetExtension(FileUpload.FileName)
Dim fileNameOnServer As String = strFileName +
Guid.NewGuid().ToString().Substring(0, 33) + fileExtension
FileUpload.SaveAs(System.IO.Path.Combine(Server.MapPath("Original/"),
fileNameOnServer))

Dim path As String = Server.MapPath("Original/" &
fileNameOnServer)
'write thumbnail
CreateImage(path, Server.MapPath(fileNameOnServer))
'write image
CreateThumbnail(path, Server.MapPath("Thumbs/" &
fileNameOnServer))

txtInfo.InnerHtml = "Das Angebot wurde erfolgreich gespeichert"
SqlDataSource1.InsertParameters("Bild").DefaultValue =
fileNameOnServer

'delete original
Dim xfile1 As String =
"C:\Inetpub\wwwroot\ticketshop\TicketModule\BACKEND\Original\" +
fileNameOnServer
File.Delete(xfile1)
End If
End Sub


thx,
christian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top