惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LINUX DO - 最新话题
G
Google Developers Blog
J
Java Code Geeks
The GitHub Blog
The GitHub Blog
F
Full Disclosure
H
Help Net Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Vercel News
Vercel News
酷 壳 – CoolShell
酷 壳 – CoolShell
Recent Announcements
Recent Announcements
Help Net Security
Help Net Security
The Hacker News
The Hacker News
IT之家
IT之家
Y
Y Combinator Blog
Martin Fowler
Martin Fowler
L
Lohrmann on Cybersecurity
C
CERT Recently Published Vulnerability Notes
V
Visual Studio Blog
博客园 - 聂微东
Hacker News: Ask HN
Hacker News: Ask HN
H
Hacker News: Front Page
Know Your Adversary
Know Your Adversary
Security Latest
Security Latest
Security Archives - TechRepublic
Security Archives - TechRepublic
Simon Willison's Weblog
Simon Willison's Weblog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Troy Hunt's Blog
Last Week in AI
Last Week in AI
Schneier on Security
Schneier on Security
N
News and Events Feed by Topic
博客园 - 【当耐特】
有赞技术团队
有赞技术团队
AWS News Blog
AWS News Blog
Blog — PlanetScale
Blog — PlanetScale
博客园_首页
Google DeepMind News
Google DeepMind News
Cloudbric
Cloudbric
N
News | PayPal Newsroom
A
About on SuperTechFans
S
Schneier on Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Hugging Face - Blog
Hugging Face - Blog
M
MIT News - Artificial intelligence
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
雷峰网
雷峰网
T
The Exploit Database - CXSecurity.com
罗磊的独立博客
K
Kaspersky official blog
The Cloudflare Blog
I
Intezer

博客园 - xixi8820

输入框验证输入数字的js 关于VS2005中GridView的自定义分页,单选、多选、排序、自增列的简单应用(转载的) 使用t-sql从身份证号中提取生日(转自别人,个人学习收藏用) 一个最简单的登录例子 js中setTimeout与setInterval的区别 js将html中的内容导出word、或者excel文件的方法 javascript 获得指定日期的临近日期的方法 asp.net 2.0 生成验证码 在Asp.Net中应用DataFormatString ASP.NET中App_Code,App_Data等文件夹的作用 javascript 客户端验证 在DataGrid中模版列显示图片 页面取物理路径和几种获取asp.net应用程序的路径 模式窗口关闭,并刷新父窗口的方法 跨页面实现多选 用window.location.href实现刷新另个框架页面 听说是个高效的分页存储过程,可以轻松应对百万数据(转) keycode 值 DataGrid点击删除按钮弹出对话框的问题
上传图片
xixi8820 · 2007-11-27 · via 博客园 - xixi8820

 1<HTML>
 2    <HEAD>
 3        <title>UpLoad</title>
 4        <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
 5        <meta name="CODE_LANGUAGE" Content="C#">
 6        <meta name="vs_defaultClientScript" content="JavaScript">
 7        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
 8        <base target="_self">
 9        <style type="text/css">
10            #myImg
11            {
12                filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);
13            }

14        
</style>
15        <script language="javascript">
16            
17        function viewfile()
18        {
19            //document.getElementById("myImg").src=document.getElementById("File1").value;
20            document.getElementById("myImg").filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = document.getElementById("File1").value;
21        }

22        
23        
</script>
24    </HEAD>
25    <body>
26        <form id="Form1" method="post" runat="server">
27            <TABLE id="Table1" cellSpacing="1" cellPadding="1" width="300" border="0">
28                <TR>
29                    <TD align="center" height="25">
30                        <asp:Image id="Image1" runat="server" ImageUrl="Images/load2.gif"></asp:Image>
31                    </TD>
32                </TR>
33                <TR>
34                    <TD align="center"><img width="80" height="80" alt="图标" id="myImg" >
35                    </TD>
36                </TR>
37                <TR>
38                    <TD align="center"><INPUT id="File1" type="file" name="File1" runat="server" onpropertychange="viewfile();"></TD>
39                </TR>
40                <TR>
41                    <TD align="center">
42                        <asp:Button id="btnUpLoad" runat="server" Text="上传" CssClass="ckpUp"></asp:Button></TD>
43                </TR>
44            </TABLE>
45        </form>
46    </body>
47</HTML>

后台代码:

  1using System;
  2using System.Collections;
  3using System.ComponentModel;
  4using System.Data;
  5using System.Drawing;
  6using System.Web;
  7using System.Text;
  8using System.Web.SessionState;
  9using System.Web.UI;
 10using System.Web.UI.WebControls;
 11using System.Web.UI.HtmlControls;
 12using System.IO;//引用File类时用到
 13
 14namespace aaaaaaaaaaaaa
 15{
 16    /// <summary>
 17    /// UpLoad 的摘要说明。
 18    /// </summary>

 19    public class UpLoad : System.Web.UI.Page
 20    {
 21        protected System.Web.UI.WebControls.Image Image1;
 22        protected System.Web.UI.WebControls.Button btnUpLoad;
 23        protected System.Web.UI.HtmlControls.HtmlInputFile File1;
 24    
 25        private void Page_Load(object sender, System.EventArgs e)
 26        {
 27            // 在此处放置用户代码以初始化页面
 28            
 29            if(!IsPostBack)
 30            {
 31                this.Image1.Visible=false;
 32            }

 33
 34        }

 35
 36        //关闭并刷新父窗口
 37        public static void CloseWin(string url)
 38        {
 39            StringBuilder str = new StringBuilder();
 40            str.Append("<script language=javascript>");
 41            str.Append("var e = (window.parent.opener == undefined) ? dialogArguments : window.parent.opener.document;");
 42            str.Append("e.location='" + url + "';");
 43            str.Append("window.close();");
 44            str.Append("</script>");
 45
 46            HttpContext.Current.Response.Write(str.ToString());
 47        }

 48
 49        Web 窗体设计器生成的代码
 70
 71        private void btnUpLoad_Click(object sender, System.EventArgs e)
 72        {
 73            string Sourcefile = this.File1.Value;
 74            if(Sourcefile=="")
 75            {
 76                Response.Write("<script>alert('请选择图片文件')</script>");
 77            }

 78            else
 79            {
 80                string fileExtName = Sourcefile.Substring(Sourcefile.LastIndexOf(".")+1,3);//取扩展名
 81
 82                if(fileExtName.ToLower() !="jpg" )//本程序暂用jpg格式
 83                {
 84                    Response.Write("请选择格式为jpg的图片文件");
 85                }

 86                else
 87                {
 88                    string ImgServerPath = Server.MapPath(".")+"/Images/UpLoad/";
 89                    string ImgServerName = "lib_"+Request.QueryString["ID"]+"."+fileExtName.ToLower();
 90
 91                    if (Request.Files.Count > 0)
 92                    {
 93                        if (Request.Files[0].FileName!="")
 94                        {
 95                            string ServerFullPath=ImgServerPath+ImgServerName;
 96                            
 97                            try
 98                            {
 99                                
100                                this.Image1.Visible=true;
101                                //删除原有图像
102                                File.Delete(ImgServerPath+"lib_"+Request.QueryString["ID"]+".jpg");
103
104                                Request.Files[0].SaveAs(ServerFullPath);
105                            }

106                            catch(System.Exception ex)
107                            {                        
108                                Response.Write("<script>alert('上传失败,文件不存在或权限不能访问!');</script>");
109                                return;
110                            }

111                            this.Image1.Visible=false;
112
113                            CloseWin("aaaa.aspx?id="+Request.QueryString["ID"].ToString());
114                        }

115                    }

116                }

117            }

118        }

119    }

120}

121