I'm creating a basic MVC Copy File App and am returning a Not All Code Paths Return a Value error in my GetSource method. I've researched the issue and have tried a few things, but the error still generates. I believe the error is in the foreach loop somewhere, but I tried returning a null afterwards, which just threw up a different error. Any help is appreciated as I am a beginner. Thanks!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
namespace April24
{
public class Andrew
{
public string Copy()
{
return "Done Copying";
}
public string GetSource() //Error is here
{
copyFiles(10);
}
public static string production = @"C:\Users\test\Desktop\Production";
public static string renameFolder = @"C:\Users\test\Desktop\RenameFolder\";
static private void copyFiles(int numberOfFiles)
{
List<string> files = System.IO.Directory.GetFiles(production, "*").ToList();
IEnumerable<string> filesToCopy = files.Where(file => file.Contains("Test_Name")).Take(10);
foreach (string file in filesToCopy)
{
string destfile = renameFolder + System.IO.Path.GetFileName(file);
System.IO.File.Copy(file, destfile, true);
};
/*tried return null; here but still threw error*/
}
}
}