Method for uploading files in ASP.NET (1)

xiaoxiao2021-03-06  69

First introduce one may be the simplest. 1: Create a new WebForm to name it. 2: Drag from the control toolbox (HTML control), add the runat = Server property, add the Name property and ID attribute. 3: Drag and drop a Button control from the web control and a Label control. 4: Double-click the Button control, add the following code in its Click event handler: if (file1.postedfile.filename! = ") {String sfile = file1.postedfile.filename; sfile = sfile.substring (sfile.lastIndexof) //")).Replace ("// "," "); string spath = appdomain.currentdomain.basedirectory.toString () sfile; file1.postedfile.saveas (spath); lblmsg.text = file has been successful Upload " spath;} else lblmsg.text =" Please select the file you want to upload "; 5: Finally, don't forget to modify the Form's properties, add the EncType property. Modified FORM code is:

now, you can run the page upload file.

转载请注明原文地址:https://www.9cbs.com/read-109382.html

New Post(0)