想做個類似163郵箱上傳附件的程序,可掛了

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;
using System.Data.OleDb;
using WebBase;

public class CUpfile
{
    string m_FileName;
    FileUpload m_File;
    public CUpfile(string strFileName,FileUpload  file)
 {
        m_FileName = strFileName;
        m_File = file;
 }
    public string GetFileName()
    {
        return m_FileName;
    }
    public FileUpload GetFile()
    {
        return m_File;
    }
}

public partial class Message_UpFile : System.Web.UI.Page
{
    static ArrayList UpFileList = new ArrayList();
    string s = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            s += "   1";
            Response.Write(s);
        }
    }

    protected void btn_UpFile_Click1(object sender, EventArgs e)
    {
        //
        string strFileName = FileUpload.PostedFile.FileName;
        if (strFileName == "")
        {
            Response.Write("<script>alert(/"上傳文件內容不能爲空!/");</script>");
            return;
        }
        //
        int nIndex = strFileName.LastIndexOf('//');
        if(nIndex < 0)
        {
            Response.Write("<script>alert(/"文件路徑有錯誤,請檢查!/");</script>");
            return;
        }
        //
        strFileName = strFileName.Substring(nIndex + 1);
        //
        int intDocLen = FileUpload.PostedFile.ContentLength;
        byte[] Docbuffer = new byte[intDocLen];
        try
        {
            System.IO.Stream objStream;
            objStream = FileUpload.PostedFile.InputStream;
            objStream.Read(Docbuffer, 0, intDocLen);
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
      
       
        string strContent = Convert.ToBase64String(Docbuffer);
        //插入數據庫或文件目錄
        }


    }
    protected void btn_Add_Click(object sender, EventArgs e)
    {
        string strFileName = FileUpload.PostedFile.FileName;
        if (strFileName == "")
        {
            Response.Write("<script>alert(/"上傳文件內容不能爲空!/");</script>");
            return;
        }
        //
        int nIndex = strFileName.LastIndexOf('//');
        if(nIndex < 0)
        {
            Response.Write("<script>alert(/"文件路徑有錯誤,請檢查!/");</script>");
            return;
        }
        //
        strFileName = strFileName.Substring(nIndex + 1);
        CUpfile aa = new CUpfile(strFileName, FileUpload);
        UpFileList.Add(aa);
       
        //
        RefreshList();
       
    }
    //刷新list
    private void RefreshList()
    {
        List_File.Items.Clear();
        for (int i = 0; i < UpFileList.Count; i++)
        {
            CUpfile ite1 = (CUpfile)UpFileList[i];
            List_File.Items.Add(ite1.GetFileName());
            //
            ImageButton btn = new ImageButton();
            btn.ImageUrl = "../images/common/green_arrow.gif";

//就在這裏掛的
            //btn.Click += new System.EventHandler(this.ImageButton_Click);
            btn.Click += new System.EventHandler(delegate(object sender, ImageClickEventArgs e) { string s = ""; });


            HyperLink lbl = new HyperLink();
            lbl.Text = ite1.GetFileName();

            Panel1.Controls.Add(lbl);
            Panel1.Controls.Add(btn);
        }
    }
    //
    protected void ImageButton_Click(object sender, ImageClickEventArgs e)
    {
        Response.Write("Bu");
    }
}
 

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章