Upload a file

0
0

I’m trying to upload a file to the server (.net 4.8), I’ve read all the forum posts and examples but I haven’t figured out how to do it yet. I tried with the Upload control and with OpenfileDialog. In the first I can’t find FileName (which I use in Asp.net), in the second if I understand correctly I should use Powershell but I can’t find the references.
Any complete examples, if possible?

This is my code in Asp.Net:

string cFilename = FileUpload1.FileName.Trim();
byte[] aFile = FileUpload1.FileBytes;

EDIT:

I try this:

private void upload1_Uploaded(object sender, UploadedEventArgs e)
{
var oFile = e.Files[0];
oFile.SaveAs(cPath + “myfile.txt”);
}

The file is saved but the app restarts.


SECOND EDIT:

I tried this too, but the application restarts.

private void upload1_Uploaded(object sender, UploadedEventArgs e)
{
var oFile = e.Files[0];
Stream oStream = oFile.InputStream;
oStream.Position = 0;

byte[] buffer = new byte[16 * 1024];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = oStream.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}

byte[] aByte = ms.ToArray();
File.WriteAllBytes(Leo.cPath + “test.txt”, aByte);
}
}

  • You must to post comments
0
0

Hi Francesco,

you’re getting the filename(s) in e.Files of the Uploaded Event.

Sample
https://github.com/iceteagroup/wisej-examples/tree/3.5/UploadFiles

Documentation
https://docs.wisej.com/api/wisej.web/content/upload

Best regards
Frank

  • Frank (ITG)
    PS: If the app restarts, you’re probably saving to the bin folder and this causes a restart of the application. In ASP.NET or Wisej.NET. Regards, Frank
  • Francesco Leo
    I had already seen the example, even if it is for .NET 7, I instead use 4.8, I found a way to manage the stream, we’ll see if everything goes well. P.S. Thanks for the info, this clarifies a lot of things for me.
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.