Click here to Skip to main content
14,364,863 members
Rate this:
Please Sign up or sign in to vote.
See more:
my model is like is
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; }
  }

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,


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 20:11pm
Rate this:
Please Sign up or sign in to vote.

Solution 2

Another way, which you can add/remove items dynamically


        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);
   
Rate this:
Please Sign up or sign in to vote.

Solution 1

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)
                   };
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

another option is you can write linq query that returns file path also

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
   
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month