[SOLVED] Saving files to server corrupts them? [VB.NET]

Answered Closed
0
0

Hello,

I am using the WiseJ Uploader to be able to upload files from the client machine to the server.

After the files are uploaded, some of the files are corrupt and cannot be opened. For example with images.

Here is my code, basically got it from here: https://wisej.com/support/question/vb-net-example-function-upload

I have 2 questions regarding working with the Uploader Control.

1: Corrupted Files

Private Sub Upload1_Uploaded(sender As Object, e As UploadedEventArgs) Handles Upload1.Uploaded
LoadFiles(e.Files)
End Sub

Private Sub LoadFiles(files As HttpFileCollection)
If files Is Nothing Then Return

If files.Count >= 1 Then
For i As Integer = 0 To files.Count – 1
ListBox1.Items.Add(files(i).FileName)
Dim fileStream = File.Create(“P:\Upload Test\” + files(i).FileName)
files(i).InputStream.Seek(i, SeekOrigin.Begin)
files(i).InputStream.CopyTo(fileStream)
fileStream.Close()
Next
End If
End Sub

Question 2:

If the client selects 1 file to upload, that gets sent to the HttpFileCollection.

If they select another file, the HttpFileCollection is overwritten. How can I keep it “alive” and just keep adding in files?

  • Dade Layer
    It seems that only the first file is working fine, all the files after the first one is corrupt
  • You must to post comments
Best Answer
1
0

Hi, Dade!

Try:

Private Sub Upload1_Uploaded(sender As Object, e As UploadedEventArgs) Handles Upload1.Uploaded
Dim I As Integer

For I = 0 To e.Files.Count – 1
e.Files(I).SaveAs(“FILE”)
Next
End Sub

Best regards,
Ulisses.

  • Dade Layer
    Hi, Is it possible to have the files upload/save to the server by calling it from another button? Also a 2nd question, when debugging I can upload files just fine. If I try to access the website on another computer on the same network and do the upload, I get something like “The file C:\Users\Admin\test.png”
  • You must to post comments
Showing 1 result