Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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;


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
C#
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;
Posted
Updated 23-Mar-17 1:56am
v2
Comments
F-ES Sitecore 23-Mar-17 7:47am    
What's wrong with the code you have?
Member 12183079 23-Mar-17 7:49am    
file path is not storing in array list
F-ES Sitecore 23-Mar-17 8:01am    
Each time you get the "path" you set all items in the array to that variable so all you'll end up with is an array where all the elements contain the last path.

1 solution

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];
 
Share this answer
 
Comments
Member 12183079 23-Mar-17 8:21am    
it is working fine but how to store value means every file storing in path string so i want to know how to store first path like in path string and second value stored in string path1 and third vaule in string path2
so please help me


means i want store every value in diffrent string
Karthik_Mahalingam 23-Mar-17 8:22am    
use array index to access each path, why to store in the path1, path2 .... , you will not know that how many files has been uploaded.
Member 12183079 23-Mar-17 8:24am    
no i know i set only 5 file can be upload so how to use in array index
Karthik_Mahalingam 23-Mar-17 8:26am    
string path1 = arr[0];
string path2 = arr[1];
string path3 = arr[2];
string path4 = arr[3];
string path5 = arr[4];
Member 12183079 23-Mar-17 8:31am    
Thank You

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900