Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
my model is like is
C#
public class MovieListModel
  {
      public int Id { get; set; }
      public List<string> FilePathList { get; set; }
      public string FileName { get; set; }
      public string Extension { get; set; }
      public string Size { get; set; }
      public DateTime CreatedTime { get; set; }
      public DateTime ModifiedTime { get; set; }
  }

C#
I Need to add assign value to the above model but the proble is adding the value to the list of string that is inside the model, List<string> FilePathList  i need something like this,


C#
var obj = new MovieListModel()
                   {
                       FileName = fi.Name,
                       FilePathList = , //  Need to add value here.
                       Count = 1,
                       Extension = fi.Extension,
                       Size = Helper.FormatBytes(fi.Length),
                       CreatedTime = fi.CreationTime,
                       ModifiedTime = File.GetLastWriteTime(item)
                   };
                   movieList.Add(obj);


What I have tried:

I have try to add the value by creating a obj of the model and try to assign a value but couldn't add the value.
Posted
Updated 29-Aug-16 19:11pm

C#
var obj = new MovieListModel()
                   {
                       FileName = fi.Name,
                       FilePathList = new List<string>{"string 1", "string 2"},
                       Count = 1,
                       Extension = fi.Extension,
                       Size = Helper.FormatBytes(fi.Length),
                       CreatedTime = fi.CreationTime,
                       ModifiedTime = File.GetLastWriteTime(item)
                   };
 
Share this answer
 
Another way, which you can add/remove items dynamically


C#
        List<string> lstPathList = new List<string> ();
        lstPathList.Add("path1");
        lstPathList.Add("path2");
        lstPathList.Add("path3");
       
var obj = new MovieListModel()
                   {
                       FileName = fi.Name,
                       FilePathList = lstPathList, // 
                       Count = 1,
                       Extension = fi.Extension,
                       Size = Helper.FormatBytes(fi.Length),
                       CreatedTime = fi.CreationTime,
                       ModifiedTime = File.GetLastWriteTime(item)
                   };
                   movieList.Add(obj);
 
Share this answer
 
another option is you can write linq query that returns file path also

C#
var obj = new MovieListModel()
           {
               FileName = fi.Name,
               FilePathList =(
                             from d in file
                             select d.FilePath
                             ),
               Count = 1,
               Extension = fi.Extension,
               Size = Helper.FormatBytes(fi.Length),
               CreatedTime = fi.CreationTime,
               ModifiedTime = File.GetLastWriteTime(item)
           };
           movieList.Add(obj);

above given answer in also true
 
Share this answer
 
v2

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