2012-05-30 61 views
4

這看起來可能是一個奇怪的問題,但我需要將我的代碼轉換爲pdf - 所以我可以將其交給pdf。是的,可悲的是學校系統要求cd上的代碼作爲pdf 。我能做的是打開我的解決方案中的每個課程並複製粘貼它。但是 - 作爲一名程序員 - 我很懶,想知道Visual Studio是否有這個功能?或者如果有其他方法?將解決方案轉換爲pdf或doc文件

編輯:第三方程序遍歷文件夾中的所有文件,打開文件並將其內容複製到pdf文件中。會做 - 也不一定在Visual Studio中。

+3

如果你的學校要求這個,肯定有人已經解決了所有的解決方案的代碼文件轉換成PDF格式的問題? –

+0

http://superuser.com/questions/389318/looking-for-software-that-will-batch-convert-a-folder-tree-containing-chm-files –

+0

米奇,這就是我的想法,爲什麼我在這裏。因爲我相信這一點,所以必須有一個工具。學校也沒有給我們任何工具。 –

回答

1

厭倦了等待,這就是我想出了:

using System; 
using System.Collections.Generic; 
using System.IO; 
using System.Linq; 
using System.Text; 

namespace GetFileContents 
{ 
    class Program 
    { 
     static string types = ".js,.cshtml,.cs,.less,.css"; 
     private static string text = ""; 
     static void Main(string[] args) 
     { 
      //This folder wraps the whole thing. 
      string folderPath = @"C:\randomFolderWhereProjectIs\"; 

      string s = IterateIt(Directory.GetDirectories(folderPath).ToList()); 
      //Save to file or whatever I just used the text visualiser in Visual Studio 
     } 

     private static string IterateIt(List<string> l) 
     { 

      foreach (var path in l) 
      { 
       var files = Directory.GetFiles(path).Select(c => new FileInfo(c)).Where(c => types.Split(',').Contains(c.Extension)); 

       foreach (var fileInfo in files) 
       { 
        text += fileInfo.Name + "\r\n"; 
        using (StreamReader reader = fileInfo.OpenText()) 
        { 
         text += reader.ReadToEnd() + "\r\n"; 
        } 
       } 
       text = IterateIt(Directory.GetDirectories(path).ToList()); 
      } 
      return text; 
     } 


    } 
} 
相關問題