简体   繁体   中英

File upload in Visual WebGUI

So I'm tasked to build a file upload for our application, which is using Visual WebGUI and therefore mostly looks like WinForms codewise.

The problem is, I don't have any clues as to where to start. I tried looking through our Download class, but it just takes a file and puts it into the response.

I tried google, but there's nothing on uploading something.

I don't understand enough of how websites work to even ask myself or google the right question. I have no Idea how a website tells the browser to get a file. And if I find out how that works, I still need to somehow get VWG to do that. I can't directly interact with the browser (except when I write javascript, but I'm not sure I can get a response from js).

Ideas and clues to where to start would be great too, I just need somewhere to start.

Let me know if you need any more information or clarification, as I'm not sure which kind of information you need for this.

Visual WebGUI has a built in Upload mechanism, called the UploadControl.

Since you're using VWG, you should check out the Companion Kit which is one of few remaining resources out there for Visual Web Gui. It gives an example of the upload control. It also gives example code, which you can download.

In short, what happens is that VWG will handle the JS components of getting the file. You don't have to worry about JavaScript, that's the point of VWG. In C#, you'll code the UploadControl, and what you "get" is the information about the file like Name, Size, MIME type, etc. Refer to the companion kit for info on this.

Steps:

1) Add the UploadControl to a form

this.mobjUploadControl = new Gizmox.WebGUI.Forms.UploadControl();

2) Wire up the UploadControl

this.mobjUploadControl.UploadFileCompleted += new Gizmox.WebGUI.Forms.UploadFileCompletedHandler(this.mobjUploadControl_UploadFileCompleted);

3) Handle the actual upload.

  private void mobjUploadControl_UploadFileCompleted(object sender, UploadCompletedEventArgs e)
  {
      UploadFileResult uploadedFile = e.Result;

      // binary data for file, can be used to store to filesystem, db, etc
      byte[] fileData = File.ReadAllBytes(uploadedFile.TempFileFullName);

      // filename of what was uploaded
      string fileName = uploadedFile.Name;
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM