locked
Need file properties from my code to be represented properly. RRS feed

  • Question

  • User-1660589204 posted

    My FileDetails Model has following properties in it:

    public partial class FileDetails
        {
            public string FileUrl { get; set; }
            public string Filename { get; set; }
            public string Case_ID { get; set; }
            public string FileType { get; set; }
            public Int64 File_Reference_Id { get; set; }
            public DateTime Created_Date { get; set; }
            public DateTime Updated_Date { get; set; }
            public string Status { get; set; }
            public string File_Id { get; set; }
            public string Preset { get; set; }
            public string Transcode_callbackUrl { get; set; }
            public string FileTranscodeJob_Id { get; set; }
            public string Transcription_callbackUrl { get; set; }
            public string jobDefinition { get; set; }
            public string TranscriptionJob_Id { get; set; }
        }

    I am unable to set these values via fileInfo type. I need to set all these values in the foreach loop for multiple files. My implementation shows compile time error:

    public Task<FileDetails> UploadFiles(string filename)
            {
                DirectoryInfo info = new DirectoryInfo(path);
                List<FileDetails> details = new List<FileDetails>();
                FileInfo[] fileInfos = info.GetFiles("*.trm");
                if (fileInfos != null)
                {
                    foreach (FileInfo fileInfo in fileInfos)
                    {
                        FileDetails detail = new FileDetails();
                        detail.FileUrl = fileInfo.Name;
                        detail.Filename = fileInfo.FullName;
                        detail.FileType = fileInfo.Extension;
                        details.Add(detail);
                    }
                }

    I need to assign the exact naming values for my code, Is there any operation for this. Please help me with this.

    Wednesday, November 11, 2020 12:32 PM

Answers

  • User303363814 posted

    FileURL is fileInfo.FullName

    FileName is fileInfo.Name

    Case_ID is int.Parse(fileInfo.Name.Split('_')[0])

    FileType is fileInfo.Extension.Split('.')[1]

    CreatedDate is fileInfo.CreationTime

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 12, 2020 11:04 AM

All replies

  • User475983607 posted

    Please take a few moments to review your code.  You have a path variable that is not defined.

    public Task<FileDetails> UploadFiles(string filename)
    {
        DirectoryInfo info = new DirectoryInfo(path);
        List<FileDetails> details = new List<FileDetails>();
        FileInfo[] fileInfos = info.GetFiles("*.trm");
        if (fileInfos != null)
        {
            foreach (FileInfo fileInfo in fileInfos)
            {
                FileDetails detail = new FileDetails();
                detail.FileUrl = fileInfo.Name;
                detail.Filename = fileInfo.FullName;
                detail.FileType = fileInfo.Extension;
                details.Add(detail);
            }
        }

    Wednesday, November 11, 2020 10:00 PM
  • User303363814 posted

    My implementation shows compile time error:

    Which line?  Exact error?

    Wednesday, November 11, 2020 10:13 PM
  • User-1660589204 posted

    Hi mgebhard, the path is defined in the constructor(dependency injection). Full code is:

     public RSBRepository(RSBContext dbContext, IConfiguration config) : base(dbContext)
            {
                _dbContext = dbContext;
                path = config["FilePath:SharedFolderPath"];
            }
            public Task<FileDetails> UploadFiles(string filename)
            {
                DirectoryInfo info = new DirectoryInfo(path);
                List<FileDetails> details = new List<FileDetails>();
                FileInfo[] fileInfos = info.GetFiles("*.trm");
                if (fileInfos != null)
                {
                    foreach (FileInfo fileInfo in fileInfos)
                    {
                        FileDetails detail = new FileDetails();
                        detail.FileUrl = fileInfo.Name;
                        detail.Filename = fileInfo.FullName;I need the file
                        detail.FileType = fileInfo.Extension;
                        details.Add(detail);
                    }
                }
                var fileDetails = JsonConvert.SerializeObject(details);
                HttpClient client = new HttpClient();
                string url = "my api address";
                HttpContent httpContent = new StringContent(fileDetails, Encoding.UTF8, "application/json");
                var response = client.PostAsync(url, httpContent);
    }

    I need the fileinfo class to take and work with my FileDetails class. I do not have that functionality. My FileDetails class is:

    public partial class FileDetails
        {
            public string FileUrl { get; set; }
            public string Filename { get; set; }
            public string Case_ID { get; set; }
            public string FileType { get; set; }
            public Int64 File_Reference_Id { get; set; }
            public DateTime Created_Date { get; set; }
            public DateTime Updated_Date { get; set; }
            public string Status { get; set; }
            public string File_Id { get; set; }
            public string Preset { get; set; }
            public string Transcode_callbackUrl { get; set; }
            public string FileTranscodeJob_Id { get; set; }
            public string Transcription_callbackUrl { get; set; }
            public string jobDefinition { get; set; }
            public string TranscriptionJob_Id { get; set; }
        }

    I need the FileInfo Class to accept the file information that meets the filter(class), so I could encapsulate this information into a custom fileDetails model object, and then serialize it as a parameter to your API.

    Thursday, November 12, 2020 6:39 AM
  • User-1660589204 posted

    Hi PaulTheSmith,

    I do not have an error, I need to modify(if possible) the FileInfo to synchronize with my FileDetails class. Class code is in the same thread as reply. I need  the FileInfo Class to accept the file information that meets the filter(FileDetails class), so I could encapsulate this information into a custom fileDetails model object, and then serialize it as a parameter to your API. Lines to customize are highlighted in yellow color.

    Thursday, November 12, 2020 6:43 AM
  • User303363814 posted

    Sry, I misread your initial post "My implementation shows compile time error:"  I thought that meant you had a compiler error ..

    It is not clear to me what you want.  Can you give an example of what file information you are want - maybe show us a sample filename and tell us which parts you want to extract.

    Thursday, November 12, 2020 6:59 AM
  • User-1660589204 posted

    Hi PaulTheSmith,

    I will need the below details from a file :

    public string FileUrl { get; set; }
            public string Filename { get; set; }
            public string Case_ID { get; set; }
            public string FileType { get; set; }
            public Int64 File_Reference_Id { get; set; }
            public DateTime Created_Date { get; set; }

    This is a part of code from my Model, I have shared in same thread. Case_Id will be part of file. File_Reference_Id is auto-generated from DB(unique ID). If file location is:  C://Docuemnts//1234555_text.trm

    FileURL: C:/Docuemnts/1234555_text.trm

    FileName: 1234555_text.trm

    Case_ID: 1234555

    FileType: trm

    File_Reference_Id: generated from DB

    Created_Date: <date from folder details> if today, 11-12-2020 16:10:00(mm-dd-yyyy hh:mm:ss)

    I hope I am clear, I need to save these values into DB. Please help me.


     

    Thursday, November 12, 2020 10:42 AM
  • User303363814 posted

    FileURL is fileInfo.FullName

    FileName is fileInfo.Name

    Case_ID is int.Parse(fileInfo.Name.Split('_')[0])

    FileType is fileInfo.Extension.Split('.')[1]

    CreatedDate is fileInfo.CreationTime

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 12, 2020 11:04 AM
  • User-1660589204 posted

    Thanks PaulTheSmith,

    Can you please give me details of how to match other properties in fileinfo as per my Model.

           
            public DateTime? UpdatedDate { get; set; }:  file updated date
            public string Status { get; set; } : to be provided in program, need to assign using fileInfo
            public string FileId { get; set; }: given by API(aplhanumeric) to be in fileinfo
            public string Preset { get; set; }: to be provided in program, need to assign using fileInfo
            public string TranscodeCallbackUrl { get; set; } to be provided in program, need to assign using fileInfo
            public string FileTranscodeJobId { get; set; } given by API(aplhanumeric) to be in fileinfo
            public string TranscriptionCallbackUrl { get; set; } to be provided in program, need to assign using fileInfo
            public string JobDefinition { get; set; } given by API(aplhanumeric) to be in fileinfo
            public string TranscriptionJobId { get; set; } given by API(aplhanumeric) to be in fileinfo
       These vales are from same model and the values will be assigned by communicating with DB. 

    Thursday, November 12, 2020 11:28 AM
  • User303363814 posted

    What problem do you have?  Show your code.

    UpdatedDate - which of the FileInfo properties do you think is closest to your concept of UpdatedDate - use that one

    Status - we have absolutely know idea what this might mean  If you don't understand the specification  you are working to then ask the people who provide the specifiication

    FileId - your specification tells you how to get this information - do it!

    etc...

    Thursday, November 12, 2020 8:36 PM