Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3672952
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:40:20+00:00 2026-05-19T02:40:20+00:00

trying to get to grips with the code of a system that has been

  • 0

trying to get to grips with the code of a system that has been passed on to me. It has been written in asp.net C# MVC.

One section of this system locates files in a folder on the server, and imports them to a database. The details for the files are kept in an excel file which is also in the same folder on the server.

Currently in the excel sheet, if there is a value under the column PDFName, the system will look for a file corresponding to that name. If there is no matching file, the system will not import the data.

What I need to do, it change it so that if there is a file, it will import the file with it’s data, however if there is not a file, it will import the data so that just the file can be added at a later date. Below is the snippet from the code where it looks for the corresponding file.

        if (!string.IsNullOrEmpty(fileRow.PDFName))
        {
            try
            {
                FileInfo matchingFile = files.First(df => (df.Extension.ToLower() == ".pdf" && df.Name.Replace(df.Extension, "").ToLower() == fileRow.PDFName));

                FTPFileEntry f = new FTPFileEntry()
                {
                    FileExtension = matchingFile.Extension,
                    FileName = matchingFile.Name,
                    Name = titleRow.PDFName,
                    Type = matchingFile.Extension.Trim('.')
                };

                fileRow.FileEntry.Add(f);
            }
            catch (InvalidOperationException)
            {

            }
        }

I’m just a bit unsure as to how to go about building in the condition if there is no matching file, do something else. I was thinking something like:

if (!string.IsNullOrEmpty(fileRow.PDFName))
        { 


            FileInfo matchingFile = files.First(df => (df.Extension.ToLower() == ".pdf" && df.Name.Replace(df.Extension, "").ToLower() == fileRow.PDFName));


            if (matchingFile != null)
            {
                FTPFileEntry f = new FTPFileEntry()
                {
                    FileExtension = matchingFile.Extension,
                    FileName = matchingFile.Name,
                    Name = titleRow.PDFName,
                    Type = matchingFile.Extension.Trim('.')
                };

                fileRow.FileEntry.Add(f);

            }
            else
            {
                //Add data to database
            }
        }

I was just wondering if I’m going in the right direction with this? Any pointers would be appreciated 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T02:40:21+00:00Added an answer on May 19, 2026 at 2:40 am

    It looks fine to me.
    You could also use the first snippet of code and add data to the database in the catch section, but catching the exception would reduce the performances (not by much, but nonetheless…)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to get to grips with Core Data and I'm having some
Trying to get the grips of best URI practice in RESTfulness... Let's say that
I'm trying to get to grips with Kendo UI, one thing they do is
I have been trying to get to grips with Hibernate's inverse attribute, and it
Currently using Telerik ASP .NET MVC Controls version 2011.2.712 Hello all, I am trying
I'm trying to get the grips of using prototypal inheritance. Here is the code
I'm trying to create a page using ASP.NET MVC 2 which shows two things:
I'm trying to get to grips with Entity Framework and there is one thing
I'm trying to get to grips with Qt's signal and slots mechanism. I have
I'm trying to get to grips with NHibernate, Fluent NHibernate and Spring. Following domain-driven

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.