zoukankan      html  css  js  c++  java
  • ASP.NET上传文件实例代码

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="FileUpload.aspx.cs" Inherits="EM_FileUpload" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>上傳文件</title>
        <base target=_self />
    </head>
    <body>
        <form id="form1" runat="server">
        <div style="margin:10px;">
            <fieldset style="300px;"><legend style="font-size:small;">上傳文件</legend>
                <table style=" 300px;">
                    <tr>
                        <td>
                            <asp:Label ID="Label1" runat="server" Text="上傳文件請控制在10M以內!" Font-Size="Small" ForeColor="Red"></asp:Label></td>
                    </tr>
                    <tr>
                        <td style=" 300px">
                            <asp:FileUpload ID="fuSelect" runat="server" Width="296px" /></td>
                    </tr>
                    <tr>
                        <td style=" 300px">
                            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
                            <asp:Button ID="btnYes" runat="server" Text=" 上 傳 "  ToolTip="確定選用此文件並退出!"
                                onclick="btnYes_Click"/>
                            &nbsp; &nbsp;&nbsp;
                            <asp:Button ID="btnNo" runat="server" Text=" 取 消 "  ToolTip="放棄選用並退出"
                                onclick="btnNo_Click" />
                            </td>
                    </tr>
                </table>
           
            </fieldset>
        </div>
        </form>
    </body>
    </html>

    //*********cs

    using System;
    using System.Data;
    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 EM_FileUpload : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Expires = 0;
            Response.Cache.SetNoStore();
            Response.AppendHeader("Pragma", "no-cache");

        }
        protected void btnYes_Click(object sender, EventArgs e)
        {
            if (fuSelect.HasFile)
            {
                try
                {
                    string FilePath = System.Web.HttpContext.Current.Request.MapPath("Datum") + "\\" + Request.QueryString["shipid"].ToString() ;
                    if (!System.IO.Directory.Exists(FilePath))
                        System.IO.Directory.CreateDirectory(FilePath);

                    fuSelect.SaveAs(FilePath + "\\" + fuSelect.FileName);
                    //Label2.Text = "客戶端路徑:" + fuSelect.PostedFile.FileName + "<br>" +
                    //              "文件名:" + System.IO.Path.GetFileName(fuSelect.FileName) + "<br>" +
                    //              "文件大小:" + fuSelect.PostedFile.ContentLength + " KB<br>";
                    //Label1.Text = System.IO.Path.GetFileName(fuSelect.FileName).ToString().Trim();
                    //Session["Shipment"] = System.IO.Path.GetFileName(fuSelect.FileName).ToString().Trim();
                    //ibtnYes.Enabled = true;
                }
                catch (Exception ex)
                {
                    Label1.Text = "發生錯誤:" + ex.Message.ToString();
                    return;
                    //ibtnYes.Enabled = false;
                }
            }
            else
            {
                Label1.Text = "請選擇要上傳的文件!";
                return;

            }

            //Page.RegisterStartupScript("MobileMSG", "<script>window.dialogArguments.document.getElementById('ctl00_ContentPlaceHolder1_lblEquPhoto').innerHTML ='" + Label1.Text.ToString() + "';</script>");
            Page.RegisterStartupScript("CancelSelect", "<script>self.close();</script>");
        }
        protected void btnNo_Click(object sender, EventArgs e)
        {
            Page.RegisterStartupScript("CancelSelect", "<script>self.close();</script>");
        }
    }

  • 相关阅读:
    Mybatis 的 xml 文件语法错误,启动项目时控制台一直循环解析但是不打印错误
    在一个由 'L' , 'R' 和 'X' 三个字符组成的字符串(例如"RXXLRXRXL")中进行移动操作。一次移动操作指用一个"LX"替换一个"XL",或者用一个"XR"替换一个"RX"。现给定起始字符串start和结束字符串end,请编写代码,当且仅当存在一系列移动操作使得start可以转换成end时, 返回True。
    【Important】数据库索引原理
    服务化的演变和负载均衡
    【问题集】redis.clients.jedis.exceptions.JedisDataException: ERR value is not an integer or out of range
    【Spring】Spring中用到的设计模式
    【设计模式】责任链模式
    【!Important】Zookeeper用来做什么的,有几种类型的节点
    【!Important】如何保证线程执行的先后顺序
    【!Important】Java线程死锁查看分析方法
  • 原文地址:https://www.cnblogs.com/vic_lu/p/1810108.html
Copyright © 2011-2022 走看看