想做个类似163邮箱上传附件的程序,可挂了

    技术2022-05-11  29

    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");    }} 

     

    最新回复(0)