2016-04-26 16 views
-2

私は基本的なMVCファイルコピーアプリケーションを作成していますが、GetSourceメソッドでNot Allコードパスを返すエラーが返されています。私は問題を調査していくつか試しましたが、エラーはまだ発生します。私はエラーがforeachループのどこかにあると信じていますが、後でnullを返そうとしたところ、別のエラーが発生しました。私が初心者なので、どんな助けもありがたいです。ありがとう!MVC、C# - すべてのコードパスではない値を返します

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*/ 

     } 
    } 
} 
+1

あなたは 'GetSource'を返すために何をしたいですか文句を言うものです、何も返しませんか? –

+4

'GetSource()'で何も返さないので(指定した場合は 'string'を返す必要があります)そして、あなたは 'copyFiles()'は 'void'です(何も返しません) –

+0

Danielに感謝します。 'production'から 'rename folder'にファイルをコピーすることになっています。このコードはコンソールアプリケーションとして動作しますが、MVCフレームワークにコピーしたときにエラーが発生しました。 – AndrewC10

答えて

3

あなたのメソッドのシグネチャはGETSOURCEは、文字列を返すと言いますが、関数本体は、コンパイラ、約

public string GetSource() //Error is here 
{ 
     copyFiles(10); 
     return "A string here" 
} 
関連する問題