locked
Save file details in my SQL database RRS feed

  • Question

  • User-1660589204 posted

    I need to save details of a file from shared folder in my SQL DB. I have created a Model as: 

    public partial class RsbfileDetail
        {
            public string FileUrl { get; set; }
            public string Filename { get; set; }
            public string CaseId { get; set; }
            public string FileType { get; set; }
            public int FileReferenceId { get; set; }
            public DateTime? CreatedDate { get; set; }
            public DateTime? UpdatedDate { get; set; }
            public string Status { get; set; }
            public string FileId { get; set; }
            public string Preset { get; set; }
            public string TranscodeCallbackUrl { get; set; }
            public string FileTranscodeJobId { get; set; }
            public string TranscriptionCallbackUrl { get; set; }
            public string JobDefinition { get; set; }
            public string TranscriptionJobId { get; set; }
        }

    While taking from folder, I need to save the highlighted fields only.  Remaining things will be saved later as the code progresses. FileReferenceID is autogenerated and unique for every file. I wrote code in C# but it returns compile time errors in a service(different file). 

    <div>

    class FilePickerService
        {
            private static string path = string.Empty;
            private static string authUrl = string.Empty;
            private static string url = string.Empty;
            private static string DownloadFileUri = string.Empty;
            public FilePickerService(IConfiguration config)
            {
                path = config["FilePath:SharedFolderPath"];
                authUrl = config["ApiUrls:authUrl"];
                url = config["ApiUrls:url"];
                DownloadFileUri = config["ApiUrls:DownloadFileUri"];
            }
            public async static void AiAuthenticate()
            {
                HttpClient client = new HttpClient();
                string authPath = authUrl + "/oauth/token";
                var parameters = new Dictionary<string, string> { { "username", "name" }, { "grant_type", "password" }, { "password", "password" } };
                var encodedContent = new FormUrlEncodedContent(parameters);
    
    
                var response = await client.PostAsync(authPath, encodedContent);
                string result = response.Content.ReadAsStringAsync().Result;
    
    
                var Bearer = result;
                AddNewFileFromFolderToDB(client,Bearer);
            }
            public static void AddNewFileFromFolderToDB(HttpClient httpclient, string result)
            {
                HttpClient client = new HttpClient();
                var Bearer = result;
    
    
                using (var db = new rsbsrdbContext())
                {
                    var file = new RsbfileDetail { FileReferenceId };
                    db.RsbfileDetails.Add(RsbfileDetail);
                    db.SaveChanges();
                }
            }
            }


    </div>

    This returns errors in the highlighted lines as:

    FileReferenceID: can not initialize type "RSBfileDetail" with a collection initializer because it does not implement "System.Collections.IEnumerable".

    FileReferenceID: The Name FileReferenceID does not exist in the current context.

    RsbfileDetail: "RsbfileDetail" is a type, which is not valid in the current context.

    How can I save the values into my Data Base fields? 
     

    Thursday, November 12, 2020 10:20 AM

Answers

  • User475983607 posted

    The initialization syntax is...

    var file = new RsbfileDetail { FileReferenceId = FileReferenceId };

    However, FileReferenceId is not declared or populated anywhere in the code.

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

All replies

  • User475983607 posted

    The initialization syntax is...

    var file = new RsbfileDetail { FileReferenceId = FileReferenceId };

    However, FileReferenceId is not declared or populated anywhere in the code.

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

    Thanks mgebhard, I have to get those values from DB. Thanks

    Thursday, November 12, 2020 1:11 PM