多图片多文件上传代码

多文件:

 

        private string UploadFile(int i)
        {
            if (!Directory.Exists(this.VtekPhotoPath))
            {
                DirectoryInfo dirinfo = Directory.CreateDirectory(this.VtekPhotoPath);
            }
            string file_name = "";
            try
            {
                //this.media = new MyUploader.HttpMedia(true);      
                //this.media.Media = this.browse.PostedFile;
                this.media = new MyUploader.HttpMedia(i);
                media.ChangePrefixAs(DateTime.Now.ToString("yyyyMMddHHmmss") + i.ToString());
               // this.media = new MyUploader.HttpMedia();
                //media.ChangePrefixAsTimeStr();
                media.SetMaxLength(10000);
                ArrayList al = new ArrayList();
                al.Add("rar");
                al.Add("zip");
                al.Add("ppt");
                al.Add("doc");
                al.Add("docx");
                al.Add("xlsx");
                al.Add("xls");
                al.Add("txt");
                media.SetFilter(al);
                if (media.Upload(this.VtekPhotoPath))
                {
                    //string sql = "select top 1 Dcontxt from tb_Doc_Share where SN='" + this.sn + "' ";
                    //file_name = MySqlBase.GetVarFromSql(sql, "Dcontxt");
                    //this.deleleFile(file_name);
                    file_name = media.GetFileName();
                }
            }
            catch (Exception Err)
            {
                this.tErrors = Err.Message;
            }
            return file_name;
        }
        private int SaveDate()
        {
            try
            {
                int i = -1;
                SqlParameter[] p = new SqlParameter[3];
                p[0] = new SqlParameter("@Thing_No", this.Tbx_TadNO.Text.Trim());
                p[1] = new SqlParameter("@IsReturn", this.Rbtn_shifouhuibao.SelectedValue);
                System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
                int file;
                string all_File_name = "";
                for (file = 0; file < files.Count; file++)
                {
                    //string photo_name = Convert.ToString(files[file]).Substring(Convert.ToString(files[file]).LastIndexOf("/") + 1) + "|";
                    string photo_name = this.UploadFile(file);
                    if (!CoolFuncs.IsNullorEmpty(photo_name))
                    {
                        all_File_name += photo_name + "|";
                    }
                }
                if (!CoolFuncs.IsNullorEmpty(all_File_name))
                {
                    p[2] = new SqlParameter("@attachment", all_File_name);
                }
                return i = MySqlBase.ExecuteSql("Tad_tad_things_atta_ADD", p);
                string sql = "select * from tad_things_atta where Thing_No='" + this.Tbx_TadNO.Text.Trim() + "'  order by AID";
                DataSet ds = MySqlBase.GetVarsAsDataSet(sql);
                GridView2.DataSource = ds;
                GridView2.DataBind();
                Page.RegisterStartupScript("yes", "<script>change2(2)</script>");
            }
            catch (Exception err)
            {
                string drr = err.Message;
                return -1;
            }
           

        }

 

 

多图片:

           

 private void initform(string pk)
    {
        if (!CoolFuncs.IsNullorEmpty(this.pk))
        {

            string sqlNewsQry = "select * from  news where SN ='" + pk + "'";
            SqlDataReader dr = MySqlBase.GetVarsAsDataReader(sqlNewsQry);
            try
            {
                if (dr.Read())
                {
                    this.txtnewtitle.Text = dr["headline"].ToString();
                    this.rbtstart.SelectedValue = dr["IsUse"].ToString();
                    this.txtcontent.Text = dr["content"].ToString();
                    string photos = dr["photos"].ToString();
                    string[] pic = photos.Split('|');
                    for (int i = 0; i < pic.Length; i++)
                    {
                        if (!CoolFuncs.IsNullorEmpty(pic[i]))
                        {
                            if (i == 0)
                            {
                                this.Div1.Visible = true;
                                this.ck1.Checked = true;
                                this.txt1.Text = this.LaurelPhotoUrl + "/" + pic[i];
                                ul1 = this.LaurelPhotoUrl + "/" + pic[i];
                            }
                            if (i == 1)
                            {
                                this.Div2.Visible = true;
                                this.ck2.Checked = true;
                                this.txt2.Text = this.LaurelPhotoUrl + "/" + pic[i];
                                ul2 = this.LaurelPhotoUrl + "/" + pic[i];
                            }
                            if (i == 2)
                            {
                                this.Div3.Visible = true;
                                this.ck3.Checked = true;
                                this.txt3.Text = this.LaurelPhotoUrl + "/" + pic[i];
                                ul3 = this.LaurelPhotoUrl + "/" + pic[i];
                            }
                            if (i == 3)
                            {
                                this.Div4.Visible = true;
                                this.ck4.Checked = true;
                                this.txt4.Text = this.LaurelPhotoUrl + "/" + pic[i];
                                ul4 = this.LaurelPhotoUrl + "/" + pic[i];
                            }
                            if (i == 4)
                            {
                                this.Div5.Visible = true;
                                this.ck5.Checked = true;
                                this.txt5.Text = this.LaurelPhotoUrl + "/" + pic[i];
                                ul5 = this.LaurelPhotoUrl + "/" + pic[i];
                            }
                        }
                    }
                }
                dr.Close();
            }
            catch (Exception err)
            {
                this.tErrors = err.Message;
            }
        }
    }

    private int DeleteItem()
    {
        string sql = "delete from news where SN='" + this.pk + "'";
        return MySqlBase.ExecuteSql(sql);
    }

    private string UploadImg(int i)
    {
        if (!Directory.Exists(this.VtekPhotoPath))
        {
            DirectoryInfo dirinfo = Directory.CreateDirectory(this.VtekPhotoPath);
        }
        string photo_name = "";
        try
        {
            this.media = new MyUploader.HttpMedia(i);                    

            media.ChangePrefixAs(DateTime.Now.ToString("yyyyMMddHHmmss") + i.ToString());
            media.SetMaxLength(500);
            if (media.UploadPhotos(this.VtekPhotoPath))
            {
                photo_name = media.GetFileName();
            }
            string a = media.ErrorMessages;
        }
        catch (Exception err)
        {
            string tErrors = err.Message;
        }
        return photo_name;
    }

    private int SaveDate()
    {
        int i = -1;
        SqlParameter[] p = new SqlParameter[7];
        p[0] = new SqlParameter("@headline", this.txtnewtitle.Text.Trim());
        p[1] = new SqlParameter("@type", "2");
        p[2] = new SqlParameter("@content", this.txtcontent.Text.Trim());
        p[3] = new SqlParameter("@isUse", this.rbtstart.SelectedValue);
        System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;      
       
        int file;
        string all_photo_name = "";
        if (this.ck1.Checked == true)
        {
            string tch = this.txt1.Text;
            all_photo_name += tch.Substring(tch.LastIndexOf("/") + 1) + "|";
        }
        else
        {
            string tch11 = this.txt1.Text;
            string picname1 = tch11.Substring(tch11.LastIndexOf("/") + 1);
            if (picname1 != "")
            {
                deleleImg(picname1);
            }
        }
        if (this.ck2.Checked == true)
        {
            string tch2 = this.txt2.Text;
            all_photo_name += tch2.Substring(tch2.LastIndexOf("/") + 1) + "|";
        }
        else
        {
            string tch12 = this.txt2.Text;
            string picname2 = tch12.Substring(tch12.LastIndexOf("/") + 1);
            if (picname2 != "")
            {
                deleleImg(picname2);
            }
        }
        if (this.ck3.Checked == true)
        {
            string tch3 = this.txt3.Text;
            all_photo_name += tch3.Substring(tch3.LastIndexOf("/") + 1) + "|";
        }
        else
        {
            string tch13 = this.txt3.Text;
            string picname3 = tch13.Substring(tch13.LastIndexOf("/") + 1);
            if (picname3 != "")
            {
                deleleImg(picname3);
            }
        }
        if (this.ck4.Checked == true)
        {
            string tch4 = this.txt4.Text;
            all_photo_name += tch4.Substring(tch4.LastIndexOf("/") + 1) + "|";
        }
        else
        {
            string tch14 = this.txt4.Text;
            string picname4 = tch14.Substring(tch14.LastIndexOf("/") + 1);
            if (picname4 != "")
            {
                deleleImg(picname4);
            }
        }
        if (this.ck5.Checked == true)
        {
            string tch5 = this.txt5.Text;
            all_photo_name += tch5.Substring(tch5.LastIndexOf("/") + 1) + "|";
        }
        else
        {
            string tch15 = this.txt5.Text;
            string picname5 = tch15.Substring(tch15.LastIndexOf("/") + 1);
            if (picname5 != "")
            {
                deleleImg(picname5);
            }
        }
        for (file = 0; file < files.Count; file++)
        {
            string photo_name = this.UploadImg(file);
            if (!CoolFuncs.IsNullorEmpty(photo_name))
            {
                all_photo_name += photo_name + "|";
            }
        }
        if (!CoolFuncs.IsNullorEmpty(all_photo_name))
        {
            p[4] = new SqlParameter("@photos", all_photo_name);
        }
        p[5] = new SqlParameter("@Sign_user",this.LoginUser.UID);
        p[6] = new SqlParameter("@SN", this.pk);
        return i = MySqlBase.ExecuteSql("Event_News_Save", p);
    }

posted @ 2008-08-05 08:32  XGU_Winner  阅读(413)  评论(0编辑  收藏  举报