如何在数组列表中存储文件路径 [英] How to store filepath in array list

查看:162
本文介绍了如何在数组列表中存储文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public void File()
    {
        if (flpProspectus.HasFile)
        {
            string fileExtension = System.IO.Path.GetExtension(flpProspectus.FileName);
            int fileSize = flpProspectus.PostedFile.ContentLength;
            HttpFileCollection hfc = Request.Files;
            for (int i = 0; i < hfc.Count; i++)
            {
                HttpPostedFile hpf = hfc[i];
                if (hpf.ContentLength > 0)
                {
                    hpf.SaveAs(Server.MapPath("~/college/fileupload1/") + System.IO.Path.GetFileName(hpf.FileName));
                    string filepath = Server.MapPath("~/college/fileupload1/");
                    string  path = filepath + hpf.FileName;
                      string[] arr = new string[5];
   
                }
                arr[0] = path;
                arr[1] = path;
                arr[2] = path;
                arr[3] = path;
                arr[4] = path;
                string s = arr[i];
               
               
            }
        }
        arr[0] = objDCI_BAL.Prospectus_mention_File1 = path;
        arr[1] = objDCI_BAL.Prospectus_mention_File2 = path;
        arr[2] = objDCI_BAL.Prospectus_mention_File3 = path;
        arr[3] = objDCI_BAL.Prospectus_mention_File4 = path;
        arr[4] = objDCI_BAL.Prospectus_mention_File5 = path;





我尝试了什么:



我希望在循环开始时存储值然后在arr [0]第二次存储中存储第一个路径存储在arr [1]第三arr [2]第四arr [3]和第五arr [4]



所以如何存储这个值

并且在存储值之后我想在此对象中获取值



What I have tried:

I want To Store Value when looping start then first path store in arr[0] second time store in arr[1] third arr[2] fourth arr[3] and fifth arr[4]

so how to store this value
and after storing value i want to fetch value in this object

arr[0] = objDCI_BAL.Prospectus_mention_File1 = path;
 arr[1] = objDCI_BAL.Prospectus_mention_File1 = path;
 arr[2] = objDCI_BAL.Prospectus_mention_File1 = path;
 arr[3] = objDCI_BAL.Prospectus_mention_File1 = path;
arr[4] = objDCI_BAL.Prospectus_mention_File1 = path;

推荐答案

在循环外声明数组并通过循环索引分配它



declare the array outside the loop and assign it through loop index

string[] arr = new string[5];
        for (int i = 0; i < hfc.Count; i++)
           {
               HttpPostedFile hpf = hfc[i];
               if (hpf.ContentLength > 0)
               {
                   hpf.SaveAs(Server.MapPath("~/college/fileupload1/") + System.IO.Path.GetFileName(hpf.FileName));
                   string filepath = Server.MapPath("~/college/fileupload1/");
                   string  path = filepath + hpf.FileName;
                    if(i<5)
                    arr[i] = path;

               }







arr[0] = path;
                arr[1] = path;
                arr[2] = path;
                arr[3] = path;
                arr[4] = path;
                string s = arr[i];


这篇关于如何在数组列表中存储文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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