将解决方案转换为pdf或doc文件

时间:2012-05-30 08:49:33

标签: visual-studio-2010 pdf

这似乎是一个奇怪的问题,但我需要将我的代码转换为pdf - 所以我可以把它交给它。可悲的是,学校系统要求cd上的代码作为pdf。我能做的是打开我的解决方案中的每个类并复制粘贴它。但是 - 作为程序员 - 我很懒,想知道Visual Studio是否有任何功能?或者,如果有其他方式?

编辑:迭代文件夹中所有文件的第三方程序,打开文件并将其内容复制到pdf文件中。也可以 - 它不必在Visual Studio中。

1 个答案:

答案 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;
        }


    }
}
相关问题