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 7493411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:56:46+00:00 2026-05-29T16:56:46+00:00

I have the following condition using in my code but that doesn’t look very

  • 0

I have the following condition using in my code but that doesn’t look very efficient,is this any better way to handle ?

if (ic = filename.Contains(".wmv"))
{
    if (bitnumber > 400)
    {
        path = "ftp://" + ftpServerIP + "/" + "media" + "/" + "lib" + "/" + programName + "/" + date + "/";
        UploadCondition(path, filename);
        //return path;
    }
}

if (ic = filename.Contains(".wmv"))
{
    if (bitnumber < 400)
    {
        path = "ftp://" + ftpServerIP + "/" + "mpegmedia" + "/" + "news" + "/" + programName + "/" + "video" + "/" + "podcast" + "/";
        UploadCondition(path, filename);
        //return path;
    }
}

if (ic = filename.Contains(".m4v"))
{
    path = "ftp://" + ftpServerIP + "/" + "mpegmedia" + "/" + "news" + "/" + programName + "/" + "video" + "/" + "podcast" + "/";
    UploadCondition(path, filename);
}

if (ic = filename.Contains(".mp4"))
{
    path = "ftp://" + ftpServerIP + "/" + "mpegmedia" + "/" + "news" + "/" + programName + "/" + "video" + "/" + "podcast" + "/";
    UploadCondition(path, filename);
}
if (ic = filename.Contains(".flv"))
{
    path = "ftp://" + ftpServerIP + "/" + "mpegmedia" + "/" + "news" + "/" + programName + "/" + "video" + "/" + "podcast" + "/";
    UploadCondition(path, filename);
}
if (ic = filename.Contains(".mpg"))
{
    path = "ftp://" + ftpServerIP + "/" + "mpegmedia" + "/" + "news" + "/" + programName + "/" + "video" + "/" + "podcast" + "/";
    UploadCondition(path, filename);
}
if (ic = filename.Contains(".aac"))
{
    path = "ftp://" + ftpServerIP + "/" + "mpegmedia" + "/" + "news" + "/" + programName + "/" + "audio" + "/" + "podcast" + "/";
    UploadCondition(path, filename);
}
if (ic = filename.Contains(".mp3"))
{
    path = "ftp://" + ftpServerIP + "/" + "mpegmedia" + "/" + "news" + "/" + programName + "/" + "audio" + "/" + "podcast" + "/";
    UploadCondition(path, filename);
}
  • 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-29T16:56:50+00:00Added an answer on May 29, 2026 at 4:56 pm

    Break it up in other classes like:

    public class AudioFileValidator
    {
        private List<string> _extensions = new List<string>{".aac", ".mp3"};
        public bool IsValid(string filename)
        {
            if (!_extensions.Contains(Path.GetExtension(filename))
                return false;
    
            //validate bitrate etc
        }
    }
    

    Usage:

    var audioValidator = new AudioFileValidator();
    if (audioValidator.IsValid(filename)) 
    {
        path = "ftp://" + ftpServerIP + "/" + "mpegmedia" + "/" + "news" + "/" + programName + "/" + "audio" + "/" + "podcast" + "/";
        UploadCondition(path, filename);
    }
    
    var videoValidator = new VideoFileValidator();
    if (videoValidator.IsValid(filename)) 
    {
        path = "ftp://" + ftpServerIP + "/" + "mpegmedia" + "/" + "news" + "/" + programName + "/" + "video" + "/" + "podcast" + "/";
        UploadCondition(path, filename);
    }
    

    By doing so you’ll get classes with a single responsibility which can be reused in other places and which are easy to unit test.


    You could even take it further and introduce a new interface called IMediaFileValidator which all validators implement. and do something like:

    foreach (var validator in validators)
    { 
        if (validator.IsValid(filename))
        {
            // use info from the validator to build the path
            var mediaName = validator.MediaName; 
            path = "ftp://" + ftpServerIP + "/" + mediaName + "/" + "news" + "/" + programName + "/" + "video" + "/" + "podcast" + "/";
            UploadCondition(path, filename);
            break;
        }
    }
    

    Which would also make your code adhere to Open/Closed principle.

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

Sidebar

Related Questions

I'm doing the following: [self.parentViewController dismissModalViewControllerAnimated:YES] This code fails using the Simulator but works
If I have the following block of code in a method (using .NET 4
I have the following if condition statement if ( (strlen($data[70])>0) || ( (remove19((trim($data[29])) ==
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I'm currently working on some concurrent code that would appear to have a few
I have the following code snippet (copy and paste into kaxaml, xamlpad, etc to
I have the following code inside a class. (It's coffeescript-- and it's for a
I have an extension method that looks like the following: //[MethodImpl(MethodImplOptions.NoOptimization)] public static IEnumerable<char>
I have a ClickOnce-deployed application and I'm currently using this to detect the first

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.