<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Top.aspx.cs" Inherits="Top" %><!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>
    <style type="text/css">
        .style1
        {
            text-align: right;
            height: 150px;
        }
        .style2
        {
            font-size: xx-large;
        }
        .style3
        {
            width: 100%;
        }
        .style4
        {
            height: 84px;
            text-align: center;
            font-size: xx-large;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div class="style1">
        <span class="style2"></span>
        <table class="style3">
            <tr>
                <td class="style4">
                            文件管理</td>
            </tr>
            <tr>
                <td>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="上传" 
            Width="80px" />
        <asp:FileUpload ID="FileUpload1" runat="server" Width="176px" />
                    <asp:DropDownList ID="DropDownList1" runat="server" Height="16px" 
                                Width="84px">
                                <asp:ListItem Value="ppt/">初一级ppt</asp:ListItem>
                                <asp:ListItem Value="word/">初一级word</asp:ListItem>
                                <asp:ListItem Value="ppt/">初二级ppt</asp:ListItem>
                                <asp:ListItem Value="word/">初二级word</asp:ListItem>
                                <asp:ListItem Value="ppt/">初三级ppt</asp:ListItem>
                                <asp:ListItem Value="word/">初三级word</asp:ListItem>
                                <asp:ListItem Value="ppt/">高一级ppt</asp:ListItem>
                                <asp:ListItem Value="word/">高一级word</asp:ListItem>
                                <asp:ListItem Value="ppt/">高二级ppt</asp:ListItem>
                                <asp:ListItem Value="word/">高二级word</asp:ListItem>
                                <asp:ListItem Value="ppt/">高三级ppt</asp:ListItem>
                                <asp:ListItem Value="word/">高三级word</asp:ListItem>
                                <asp:ListItem Value="ppt/">通知ppt</asp:ListItem>
                                <asp:ListItem Value="word/">通知word</asp:ListItem>
                            </asp:DropDownList>
        <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="下载" 
            Width="80px" />
        <asp:Button ID="Button3" runat="server" onclick="Button3_Click" Text="删除" />
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;public partial class Top : System.Web.UI.Page
{
    string downpath = "";
    string mpath="";
    protected void Page_Load(object sender, EventArgs e)
    {
            if (Session["dlm"].ToString() == "admin")
            {
                Button3.Enabled = true;
            }
            else
                Button3.Enabled = false;
            if (!IsPostBack)
            {
                select();
            }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //if (Session["dlm"].ToString() != "")
        //{
            string filePath = "", fileExtName = "", mFileName;
            if ("" != FileUpload1.PostedFile.FileName)
            {
                select();
                filePath = FileUpload1.PostedFile.FileName;
                fileExtName = filePath.Substring(filePath.LastIndexOf(".") + 1);
                if (fileExtName == "doc" || fileExtName == "ppt")
                {
                    try
                    {
                        mFileName = filePath.Substring(filePath.LastIndexOf("\\") + 1);
                        FileUpload1.PostedFile.SaveAs(mpath+"\\"+DropDownList1.SelectedValue+mFileName);
                        Response.Write("<script language =javascript>alert('上传成功');history.back();</script>");
                    }
                    catch (Exception error)
                    {
                        Response.Write("<script language =javascript>alert('" + error.ToString() + "')</script>");
                    }
                }
                else
                {
                    Response.Write("<script language =javascript>alert('文件格式不对');history.back();</script>");
                    return;
                }
            }
            else
            {
                Response.Write("<script language =javascript>alert('请选择文件');history.back();</script>");
            }
        //}
        //else
        //{
        //    Response.Write("<script language =javascript>alert('请先登陆');history.back();</script>");
        //    return;
        //}
    }
    public void select()
    {
        switch (DropDownList1.SelectedItem.Text)
        {
            case "初一级ppt":
                mpath = Server.MapPath("初一级");
                break;
            case "初一级word":
                mpath = Server.MapPath("初一级");
                break;
            case "初二级ppt":
                mpath = Server.MapPath("初二级");
                break;
            case "初二级word":
                mpath = Server.MapPath("初二级");
                break;
            case "初三级ppt":
                mpath = Server.MapPath("初三级");
                break;
            case "初三级word":
                mpath = Server.MapPath("初三级");
                break;
            case "高一级ppt":
                mpath = Server.MapPath("高一级");
                break;
            case "高一级word":
                mpath = Server.MapPath("高一级");
                break;
            case "高二级ppt":
                mpath = Server.MapPath("高二级");
                break;
            case "高二级word":
                mpath = Server.MapPath("高二级");
                break;
            case "高三级ppt":
                mpath = Server.MapPath("高三级");
                break;
            case "高三级word":
                mpath = Server.MapPath("高三级");
                break;
            case "通知ppt":
                mpath = Server.MapPath("通知");
                break;
            case "通知word":
                mpath = Server.MapPath("通知");
                break;
        }
    }