• Asp.net 2.0 FileUpload 控件的用法


    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" target="_blank">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>">
    
    <html>
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:FileUpload ID="FileUpload1" runat="server" />
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="FileUpload1"
                ErrorMessage="必须是 jpg或者gif文件" ValidationExpression="^(([a-zA-Z]:)|(\\{2}\W+)\$?)(\\(\W[\W].*))+(.jpg|.Jpg|.gif|.Gif)$"></asp:RegularExpressionValidator>
        </form>
    </body>
    </html>
    
    
    using System;
    using System.Data;
    using System.Data.Sql;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
    
        protected void Button1_Click(object sender, EventArgs e)
        {
            String savePath = @"F:\wwwroot\cookie\temp\";
            if (FileUpload1.HasFile)
            {
                String filename;
                filename = FileUpload1.FileName;
                savePath +=filename;
                FileUpload1.SaveAs(savePath);
                Page.Response.Write(FileUpload1.PostedFile.ContentType + FileUpload1.PostedFile.ContentLength);
    
            }
            else
            {
                Page.Response.Write("fff");
            }
        }
    }
    
    
    
  • 相关阅读:
    探偵ガリレオー転写る 完了
    探偵ガリレオー転写る3
    探偵ガリレオー転写る2
    探偵ガリレオー転写る1
    探偵ガリレオ 燃えるまで
    探偵ガリレオ2
    探偵ガリレオ1
    【转】2014找工作----扎实的基础和开阔的视野是企业最看重的因素
    三种交换两个整数的方法
    计算十进制整数的二进制中的1的数目
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/1743343.html
Copyright © 2020-2023  润新知