如何在提交单个按钮上多个文件上传多个ASP文件上传控件 [英] How to multiple file upload multi ASP file upload control on submit single button

查看:52
本文介绍了如何在提交单个按钮上多个文件上传多个ASP文件上传控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  public   void  FileUpload1()
{
if (flpProspectus.HasFile)
{

string fileExtension = System.IO.Path.GetExtension(flpProspectus.FileName);
int fileSize = flpProspectus.PostedFile.ContentLength;
HttpFileCollection hfc = Request.Files;
{
string [] arr = new 字符串 [ 5 ];

for int i = 0 ; i < hfc.Count; i ++)
{
if (hfc.GetKey(i)== ctl00 $ ContentPlaceHolder1 $ flpProspectus
{
HttpPostedFile hpf = hfc [i];
if (hpf.ContentLength > 0
{
hpf.SaveAs(Server.MapPath( 〜/ College / fileupload3 /)+ System.IO.Path.GetFileName(hpf.FileName));
string filepath = Server.MapPath( 〜/学院/ fileupload3 /);
string pathx = 〜/ College / fileupload3 / + hpf.FileName;
if (i < 5
{
arr [i] = pathx;
path1 = arr [ 0 ]; path2 = arr [ 1 ]; path3 = arr [ 2 ]; path4 = arr [ 3 ]; path5 = arr [ 4 ];

}

}
}
}
}
}
}

public void FileUpload2()
{
if (flpOrientation.HasFile)
{
string fileExtension = System.IO.Path.GetExtension(flpOrientation.FileName );
int fileSize = flpOrientation.PostedFile.ContentLength;
HttpFileCollection hfc = Request.Files;
string [] arr = new string [ 5 ];
for int i = 0 ; i < hfc.Count; i ++)
{
if (hfc.GetKey(i)== ctl00 $ ContentPlaceHolder1 $ flpOrientation
{
HttpPostedFile hpf = hfc [i];
if (hpf.ContentLength > 0
{
hpf.SaveAs(Server.MapPath( 〜/ College / fileupload4 /)+ System.IO.Path.GetFileName(hpf.FileName));
string filepath = Server.MapPath( 〜/学院/ fileupload4 /);
string pathy = fileupload4 / + hpf.FileName;
if (i < 5
{
arr [i] = pathy;
path6 = arr [ 0 ]; path7 = arr [ 1 ]; path8 = arr [ 2 ]; path9 = arr [ 3 ]; path10 = arr [ 4 ];

}

}
}
}
}
}
public void FileUpload3()
{
if ( flpEnquiry.HasFile)
{
string fileExtension = System.IO.Path.GetExtension(flpEnquiry.FileName);
int fileSize = flpEnquiry.PostedFile.ContentLength;
HttpFileCollection hfc = Request.Files;
string [] arr = new string [ 5 ];
for int i = 0 ; i < hfc.Count; i ++)
{
if (hfc.GetKey(i)== ctl00 $ ContentPlaceHolder1 $ flpEnquiry
{
HttpPostedFile hpf = hfc [i];
if (hpf.ContentLength > 0
{
hpf.SaveAs(Server.MapPath( 〜/ College / fileupload5 /)+ System.IO.Path.GetFileName(hpf.FileName));
string filepath = Server.MapPath( 〜/学院/ fileupload5 /);
string path = fileupload5 / + hpf.FileName;
if (i < 5
{
arr [i] = path;
path11 = arr [ 0 ]; path12 = arr [ 1 ]; path13 = arr [ 2 ]; path14 = arr [ 3 ]; path15 = arr [ 4 ];
}
}

}
}
}

}
public void FileUpload4()
{
if ( flpPunishment.HasFile)
{
string fileExtension = System.IO.Path.GetExtension(flpPunishment.FileName);
int fileSize = flpPunishment.PostedFile.ContentLength;
HttpFileCollection hfc = Request.Files;
string [] arr = new string [ 5 ];
for int i = 0 ; i < hfc.Count; i ++)
{
if (hfc.GetKey(i)== ctl00 $ ContentPlaceHolder1 $ flpPunishment
{
HttpPostedFile hpf = hfc [i];
if (hpf.ContentLength > 0
{
hpf.SaveAs(Server.MapPath( 〜/ College / fileupload6 /)+ System.IO.Path.GetFileName(hpf.FileName));
string filepath = Server.MapPath( 〜/学院/ fileupload6 /);
string path = fileupload6 / + hpf.FileName;
if (i < 5
{
arr [i] = path;
path16 = arr [ 0 ]; path17 = arr [ 1 ]; path18 = arr [ 2 ]; path19 = arr [ 3 ]; path20 = arr [ 4 ];
}
}

}
}
}

}
public void FileUpload5()
{
if ( flpnooffir.HasFile)
{
string fileExtension = System.IO.Path.GetExtension(flpnooffir.FileName);
int fileSize = flpnooffir.Po​​stedFile.ContentLength;
HttpFileCollection hfc = Request.Files;
string [] arr = new string [ 9 ];
for int i = 0 ; i < hfc.Count; i ++)
{
if (hfc.GetKey(i)== ctl00 $ ContentPlaceHolder1 $ flpnooffir
{
HttpPostedFile hpf = hfc [i];
if (hpf.ContentLength > 0
{
hpf.SaveAs(Server.MapPath( 〜/ College / fileupload7 /)+ System.IO.Path.GetFileName(hpf.FileName));
string filepath = Server.MapPath( 〜/学院/ fileupload7 /);
string path = fileupload7 / + hpf.FileName;
if (i < 5
{
arr [i] = path;
path21 = arr [ 0 ]; path22 = arr [ 1 ]; path23 = arr [ 2 ]; path24 = arr [ 3 ]; path25 = arr [ 4 ];

}
}
}
}
}

}





我尝试了什么:



上面我发布你我的代码我多次使用文件上传我面临问题

当我选择文件为第一个asp控件id-flpProspectus它工作正常

但是当我选择文件为第二个asp控件id-flpOrientation它工作不正常我正在使用foreeach循环但不工作



所以请帮助我

解决方案

ContentPlaceHolder1


flpProspectus)
{
HttpPostedFile hpf = hfc [i];
if (hpf.ContentLength > 0
{
hpf.SaveAs(Server.MapPath( 〜/ College / fileupload3 /)+ System.IO。 Path.GetFileName(hpf.FileName));
string filepath = Server.MapPath( 〜/学院/ fileupload3 /);
string pathx = 〜/ College / fileupload3 / + hpf.FileName;
if (i < 5
{
arr [i] = pathx;
path1 = arr [ 0 ]; path2 = arr [ 1 ]; path3 = arr [ 2 ]; path4 = arr [ 3 ]; path5 = arr [ 4 ];

}

}
}
}
}
}
}

public void FileUpload2()
{
if (flpOrientation.HasFile)
{
string fileExtension = System.IO.Path.GetExtension(flpOrientation.FileName );
int fileSize = flpOrientation.PostedFile.ContentLength;
HttpFileCollection hfc = Request.Files;
string [] arr = new string [ 5 ];
for int i = 0 ; i < hfc.Count; i ++)
{
if (hfc.GetKey(i)== ctl00


ContentPlaceHolder1

public void FileUpload1()
    {
        if (flpProspectus.HasFile)
        {

            string fileExtension = System.IO.Path.GetExtension(flpProspectus.FileName);
            int fileSize = flpProspectus.PostedFile.ContentLength;
            HttpFileCollection hfc = Request.Files;             
            {
                string[] arr = new string[5];

                for (int i = 0; i < hfc.Count; i++)
                {
                    if (hfc.GetKey(i) == "ctl00$ContentPlaceHolder1$flpProspectus")
                    {
                        HttpPostedFile hpf = hfc[i];
                        if (hpf.ContentLength > 0)
                        {
                            hpf.SaveAs(Server.MapPath("~/College/fileupload3/") + System.IO.Path.GetFileName(hpf.FileName));
                           string filepath = Server.MapPath("~/College/fileupload3/");
                           string pathx = "~/College/fileupload3/" + hpf.FileName;
                            if (i < 5)
                            {
                                arr[i] = pathx;
                                path1 = arr[0]; path2 = arr[1]; path3 = arr[2]; path4 = arr[3]; path5 = arr[4];

                            }

                        }
                    }
                }
            }
        }      
    }

    public void FileUpload2()
    {
        if (flpOrientation.HasFile)
        {
            string fileExtension = System.IO.Path.GetExtension(flpOrientation.FileName);
            int fileSize = flpOrientation.PostedFile.ContentLength;
            HttpFileCollection hfc = Request.Files;
            string[] arr = new string[5];
            for (int i = 0; i < hfc.Count; i++)
            {
                if (hfc.GetKey(i) == "ctl00$ContentPlaceHolder1$flpOrientation")
                {
                    HttpPostedFile hpf = hfc[i];
                    if (hpf.ContentLength > 0)
                    {
                        hpf.SaveAs(Server.MapPath("~/College/fileupload4/") + System.IO.Path.GetFileName(hpf.FileName));
                        string filepath = Server.MapPath("~/College/fileupload4/");
                        string pathy = "fileupload4/" + hpf.FileName;
                        if (i < 5)
                        {
                            arr[i] = pathy;
                            path6 = arr[0]; path7 = arr[1]; path8 = arr[2]; path9 = arr[3]; path10 = arr[4];

                        }

                    }
                }
            }
        }
    }
    public void FileUpload3()
    {
        if (flpEnquiry.HasFile)
        {
            string fileExtension = System.IO.Path.GetExtension(flpEnquiry.FileName);
            int fileSize = flpEnquiry.PostedFile.ContentLength;
            HttpFileCollection hfc = Request.Files;
            string[] arr = new string[5];
            for (int i = 0; i < hfc.Count; i++)
            {
                if (hfc.GetKey(i) == "ctl00$ContentPlaceHolder1$flpEnquiry")
                {
                    HttpPostedFile hpf = hfc[i];
                    if (hpf.ContentLength > 0)
                    {
                        hpf.SaveAs(Server.MapPath("~/College/fileupload5/") + System.IO.Path.GetFileName(hpf.FileName));
                        string filepath = Server.MapPath("~/College/fileupload5/");
                        string path = "fileupload5/" + hpf.FileName;
                        if (i < 5)
                        {
                            arr[i] = path;
                            path11 = arr[0]; path12 = arr[1]; path13 = arr[2]; path14 = arr[3]; path15 = arr[4];
                        }
                    }

                }
            }
        }

    }
    public void FileUpload4()
    {
        if (flpPunishment.HasFile)
        {
            string fileExtension = System.IO.Path.GetExtension(flpPunishment.FileName);
            int fileSize = flpPunishment.PostedFile.ContentLength;
            HttpFileCollection hfc = Request.Files;
            string[] arr = new string[5];
            for (int i = 0; i < hfc.Count; i++)
            {
                if (hfc.GetKey(i) == "ctl00$ContentPlaceHolder1$flpPunishment")
                {
                    HttpPostedFile hpf = hfc[i];
                    if (hpf.ContentLength > 0)
                    {
                        hpf.SaveAs(Server.MapPath("~/College/fileupload6/") + System.IO.Path.GetFileName(hpf.FileName));
                        string filepath = Server.MapPath("~/College/fileupload6/");
                        string path = "fileupload6/" + hpf.FileName;
                        if (i < 5)
                        {
                            arr[i] = path;
                            path16 = arr[0]; path17 = arr[1]; path18 = arr[2]; path19 = arr[3]; path20 = arr[4];
                        }
                    }

                }
            }
        }

    }
    public void FileUpload5()
    {
        if (flpnooffir.HasFile)
        {
            string fileExtension = System.IO.Path.GetExtension(flpnooffir.FileName);
            int fileSize = flpnooffir.PostedFile.ContentLength;
            HttpFileCollection hfc = Request.Files;
            string[] arr = new string[9];
            for (int i = 0; i < hfc.Count; i++)
            {
                if (hfc.GetKey(i) == "ctl00$ContentPlaceHolder1$flpnooffir")
                {
                    HttpPostedFile hpf = hfc[i];
                    if (hpf.ContentLength > 0)
                    {
                        hpf.SaveAs(Server.MapPath("~/College/fileupload7/") + System.IO.Path.GetFileName(hpf.FileName));
                        string filepath = Server.MapPath("~/College/fileupload7/");
                        string path = "fileupload7/" + hpf.FileName;
                        if (i < 5)
                        {
                            arr[i] = path;
                            path21 = arr[0]; path22 = arr[1]; path23 = arr[2]; path24 = arr[3]; path25 = arr[4];

                        }
                    }
                }
            }
        }

    }



What I have tried:

Above i Post You my Code i am using multiple time file upload i am facing problem
when i choose file for first asp control id-flpProspectus it is working fine
but when i choose file for second asp control id-flpOrientation it is not working properly i am using foreeach loop but not working

so please help me

解决方案

ContentPlaceHolder1


flpProspectus") { HttpPostedFile hpf = hfc[i]; if (hpf.ContentLength > 0) { hpf.SaveAs(Server.MapPath("~/College/fileupload3/") + System.IO.Path.GetFileName(hpf.FileName)); string filepath = Server.MapPath("~/College/fileupload3/"); string pathx = "~/College/fileupload3/" + hpf.FileName; if (i < 5) { arr[i] = pathx; path1 = arr[0]; path2 = arr[1]; path3 = arr[2]; path4 = arr[3]; path5 = arr[4]; } } } } } } } public void FileUpload2() { if (flpOrientation.HasFile) { string fileExtension = System.IO.Path.GetExtension(flpOrientation.FileName); int fileSize = flpOrientation.PostedFile.ContentLength; HttpFileCollection hfc = Request.Files; string[] arr = new string[5]; for (int i = 0; i < hfc.Count; i++) { if (hfc.GetKey(i) == "ctl00


ContentPlaceHolder1


这篇关于如何在提交单个按钮上多个文件上传多个ASP文件上传控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆