今天周二的任务完成情况 张孝祖

从周一开始,到今天我学会了upload,download功能中的upload功能,可以上传任意格式的文件到指定文件夹下了,嘿嘿

代码如下

复制代码
using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.IO;

public partial class upload : System.Web.UI.Page

{

   public string title = null;           //标题

   public string keyWord = null;         //关键词

   public string author = null;          //作者

   public string filetype = null;        //类型

    protected void Page_Load(object sender, EventArgs e)

    {

       

    }//初始化页面

    protected void OK_Click(object sender, EventArgs e)   //点击上传时

    {

        //Response.Redirect();

        title = Title.Text;

        keyWord = Keyword.Text;

        author = Author.Text;

        filetype = Type.Text;

        if (title == null||filetype==null)    

        {

        }

        else

        {

            if (fu.HasFile == true)

            {

                fu.SaveAs(MapPath("UploadFiles/" + fu.FileName));

            }

        }

    }

    

}
复制代码

其实用input file 控件好像也能实现,但是我真是失败了好多次,痛定思痛就决定直接用FileUpload;页面设计代码如下

复制代码
<!DOCTYPE html>



<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <title></title>

    <style type="text/css">

        .auto-style1

        {

            text-align: center;

        }

    </style>

</head>

<body>

    <form id="form1" runat="server">

    <div class="auto-style1">

        <asp:Label ID="Top" runat="server" Text="题目(必填)"></asp:Label>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

        <asp:Label ID="Author1" runat="server" Text="作者"></asp:Label>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

        <asp:Label ID="Type1" runat="server" Text="文件类型"></asp:Label>

        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

        <asp:Label ID="Keyword1" runat="server" Text="关键字"></asp:Label>

       

        <br />

        <asp:TextBox ID="Title" runat="server" Width="83px"></asp:TextBox>

&nbsp;

        <asp:TextBox ID="Author" runat="server" Width="98px"></asp:TextBox>

&nbsp;&nbsp;&nbsp;

        <asp:TextBox ID="Type" runat="server" Width="102px"></asp:TextBox>

&nbsp;&nbsp;&nbsp;

        <asp:TextBox ID="Keyword" runat="server" Width="102px"></asp:TextBox>

        <br />

        <br />

        <asp:FileUpload ID="fu" runat="server"/><br/>

        <asp:Button ID="btnSure" runat="server" OnClick="OK_Click" Text="上传文件到服务器">

        </asp:Button>

    </div>

    </form>

    <p>

        &nbsp;</p>

</body>

</html>
复制代码

以上就是upload功能,图形界面未处理是这样的

你可能感兴趣的:(任务)