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

  • SEARCH
  • Home
  • 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 847991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:52:32+00:00 2026-05-15T06:52:32+00:00

I have written List<Attachment> lstAttachment = new List<Attachment>(); //Check if any error file is

  • 0

I have written

List<Attachment> lstAttachment = new List<Attachment>();

            //Check if any error file is present in which case it needs to be send
            if (new FileInfo(Path.Combine(errorFolder, errorFileName)).Exists)
            {
                Attachment unprocessedFile = new Attachment(Path.Combine(errorFolder, errorFileName));
                lstAttachment.Add(unprocessedFile);
            }
            //Check if any processed file is present in which case it needs to be send
           if (new FileInfo(Path.Combine(outputFolder, outputFileName)).Exists)
            {
                Attachment processedFile = new Attachment(Path.Combine(outputFolder, outputFileName));
                lstAttachment.Add(processedFile);
            }

Working fine and is giving the expected output.

Basically I am attaching the file to the list based on whether the file is present or not.

I am looking for any other elegant solution than the one I have written.

Reason: Want to learn differnt ways of representing the same program.

I am using C#3.0

Thanks.

  • 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-15T06:52:32+00:00Added an answer on May 15, 2026 at 6:52 am

    Is it looks better?

    ...
    
    var lstAttachment = new List<Attachment>();
    string errorPath = Path.Combine(errorFolder, errorFileName);
    string outputPath = Path.Combine(outputFolder, outputFileName);
    
    AddAttachmentToCollection(lstAttachment, errorPath);
    AddAttachmentToCollection(lstAttachment, outputPath);
    
    ...
    
    public static void AddAttachmentToCollection(ICollection<Attachment> collection, string filePath)
    {
        if (File.Exists(filePath))
        {
            var attachment = new Attachment(filePath);
            collection.Add(attachment);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a simple CRUD form which has one select list. However the
I have written this program, which sorts some ints using a functor: #include<iostream> #include<list>
I have written List<int> Uids = new List<int>(); Uids = (from returnResultSet in ds.ToList()
I have written a method which is public List<List<object>> Fetch(string data) , inside I
I have written python scripts to list repositories and commits. To create a new
I have written this method which given a number and a list will return
I have written a program which writes a list of data to a '.dat'
I have written a plugin for Wordpress which generates a jQuery.accordion list of content
I have written a code to add a new member to a list .
I have written a cascading drop down list using JQuery. The code that I

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.