当前位置:首页 > 网络编程 > WEB编程 > ASP.net > 一个简单的文件上传功能控件

一个简单的文件上传功能控件

点击次数:15 次 发布日期:2008-11-26 23:44:41 作者:源代码网
源代码网推荐 总在用别人的控件,第一次想自己写个控件。于是写了个简单的小控件,主要是用于自己学习和其他想尝试写控件的朋友,请多多指教。
源代码网推荐改控件主要作用是将本地图片上传到自定义目录。
源代码网推荐using System;
源代码网推荐using System.Web.UI;
源代码网推荐using System.Web.UI.WebControls;
源代码网推荐using System.ComponentModel;
源代码网推荐using System.Web.UI.HtmlControls;
源代码网推荐using System.IO;
源代码网推荐
源代码网推荐namespace UpLoadImage
源代码网推荐{
源代码网推荐 /// <summary>
源代码网推荐 ///作者:DarkAngel 2004-10-27日创建
源代码网推荐 ///支持图片上传到服务器功能
源代码网推荐 /// </summary>
源代码网推荐 [DefaultProperty("Text"),
源代码网推荐 ToolboxData(@"<{0}:UpImage runat=server></{0}:UpImage>")]
源代码网推荐 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("文件大小")
源代码网推荐 ]
源代码网推荐 public int FileLength
源代码网推荐 {
源代码网推荐 set{filelength=value;}
源代码网推荐 get{return filelength;}
源代码网推荐 }
源代码网推荐
源代码网推荐 [
源代码网推荐 DescriptionAttribute("图片名字")
源代码网推荐 ]
源代码网推荐 public string ImageUrl
源代码网推荐 {
源代码网推荐 set{imageUrl=value;}
源代码网推荐 get{return imageUrl;}
源代码网推荐 }
源代码网推荐
源代码网推荐 [
源代码网推荐 DescriptionAttribute("文件路径")
源代码网推荐 ]
源代码网推荐 public string MyDirectory
源代码网推荐 {
源代码网推荐 get{return mydirectory;}
源代码网推荐 set{mydirectory=value;}
源代码网推荐 }
源代码网推荐
源代码网推荐 [
源代码网推荐 DescriptionAttribute("图片的相对地址")
源代码网推荐 ]
源代码网推荐 public string Logo
源代码网推荐 {
源代码网推荐
源代码网推荐 get{return LogoURL;}
源代码网推荐 set{LogoURL=value;}
源代码网推荐 }
源代码网推荐
源代码网推荐 [
源代码网推荐 DescriptionAttribute("是否显示图片")
源代码网推荐 ]
源代码网推荐 public string vPicture
源代码网推荐 {
源代码网推荐 set{vpicture=value;}
源代码网推荐 get{return vpicture;}
源代码网推荐 }
源代码网推荐
源代码网推荐 private void mybutton_Click(object sender, System.EventArgs e)
源代码网推荐 {
源代码网推荐
源代码网推荐 if(!fileUpload.Value.ToString().Equals(""))
源代码网推荐 {
源代码网推荐 LogoURL=fileUpload.PostedFile.FileName.ToString();
源代码网推荐
源代码网推荐 LogoURL=LogoURL.Substring(LogoURL.LastIndexOf("."),(LogoURL.Length-LogoURL.LastIndexOf(".")));
源代码网推荐 if(fileUpload.PostedFile.ContentLength>filelength)
源代码网推荐 {
源代码网推荐 myscript("图片超过指定大小!");
源代码网推荐
源代码网推荐 }
源代码网推荐 else
源代码网推荐 {
源代码网推荐 if(LogoURL.Equals(".jpg") || 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(Page.Server.MapPath(" ")+"\"+LogoURL);
源代码网推荐
源代码网推荐
源代码网推荐
源代码网推荐
源代码网推荐 if(vpicture.Equals("1"))
源代码网推荐 {
源代码网推荐 Label1.Text="<img width="100" heigth="100" src="http://www.zzchn.com/edu/20071103/"+LogoURL+"">";
源代码网推荐 }
源代码网推荐
源代码网推荐 myscript("图片上传成功!");
源代码网推荐
源代码网推荐 }
源代码网推荐 else
源代码网推荐 {
源代码网推荐 myscript("文件类型不对!");
源代码网推荐
源代码网推荐 }
源代码网推荐
源代码网推荐 }
源代码网推荐 }
源代码网推荐
源代码网推荐 }
源代码网推荐 protected void myscript(string java)
源代码网推荐 {
源代码网推荐 Page.RegisterStartupscript("fsf","<script language=javascript>alert(""+java+"");</script>");
源代码网推荐
源代码网推荐 }
源代码网推荐
源代码网推荐 protected override void CreateChildControls()
源代码网推荐 {
源代码网推荐 mybutton=new Button();
源代码网推荐 fileUpload=new HtmlInputFile();
源代码网推荐 Label1=new Label();
源代码网推荐 mybutton.Text="提交";
源代码网推荐
源代码网推荐 this.Controls.Add(fileUpload);
源代码网推荐 this.Controls.Add(mybutton);
源代码网推荐 this.Controls.Add(new LiteralControl("<p>"));
源代码网推荐 this.Controls.Add(Label1);
源代码网推荐 this.Controls.Add(new LiteralControl("</p>"));
源代码网推荐 mybutton.Click+=new EventHandler(mybutton_Click);
源代码网推荐
源代码网推荐 }
源代码网推荐 }
源代码网推荐}
源代码网推荐
源代码网推荐

源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华