A simple file upload function control (original)

xiaoxiao2021-03-06  72

That is always using others, I want to write a control yourself for the first time. So I wrote a simple small control, mainly for my own learning and other friends who want to try to write controls, please advise. The main role of the modified part is to upload local images to the custom directory. Using system.web.ui; using system.web.ui.webcontrols; using system.componentmodel; using system.web.ui.htmlcontrols; using system.io;

namespace UpLoadImage {///

/// Author: DarkAngel 2004- 10-27 days /// support to create pictures uploaded to the server function /// [DefaultProperty ( "Text"), ToolboxData (@ " <{0}: UpImage runat = server> ")] public class UpImage: Control, INamingContainer {protected int filelength; protected string imageUrl; protected string mydirectory; static string LogoURL; protected string vpicture; public Button mybutton; public HtmlInputFile fileUpload; public Label Label1; public UpImage () {this.EnsureChildControls ();} [Bindable (true), Category ( "Appearance"), DefaultValue ( "")] [DescriptionAttribute ( "file size") ] public int fileLength {set {filelength = value;} get {return filelength;}} [DescriptionAttribute ( "image name")] public string imageUrl {set {imageUrl = value;} get {return imageUrl;}} [DescriptionAttribute ( " File path ")] public string mydirectory;} set {mydirectory = value;}} [descriptionAttribute (" Picture relative address ")] public string logo { Get {returourn;} set {logourl = value;}} [DescriptionAttribute "] public string vPicture {set {vPicture = value;} get {return vPicture;}}

private void mybutton_Click (object sender, System.EventArgs e) {if {LogoURL = fileUpload.PostedFile.FileName.ToString () (fileUpload.Value.ToString () Equals ( "")!.); LogoURL = LogoURL.Substring (LogoURL .Lastindexof ("."), (Logourl.Length-log.lastIndexof (".")); If (fileUpload.postedfile.contentLength> FileLength) {myscript ("picture exceeds the specified size!");} Else {ix (Logourl.Equals) || logourl.equals (". Bmp") || logourl.equals (". Gif")) {

Logourl = MyDirectory "//" imageurl logourl; mydirectory = page.server.mappath ("") "//" mydirectory;

IF (Directory.exists (MyDirectory)) {} else {Directory.createdIRectory (MyDirectory);} fileupload.postedfile.saveas (") " // " logourl);

IF (VPicture.Equals) {label1.text = "");

}

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

New Post(0)