//http://stackoverflow.com/questions/5826649/returning-a-file-to-view-download-in-asp-net-mvc

        // I have file not found issue
        // here is a work around
        // https://github.com/aspnet/Mvc/issues/5053
        public IActionResult GetKindleFile(string url)
        {
            // check domain
            var firstPageUri = new Uri(url);

            if (firstPageUri.Host.Contains("thuvienhoasen.org"))
            {
                var thuvienhoasen = new ThuVienHoaSen();
                var bookHelper    = new BookHelper(thuvienhoasen);
                //bookHelper.DownloadFolder = AppContext.BaseDirectory; // in case web app cannot access to a file outside of its folder
                // var firstUrlPath = @"/a17221/ban-do-tu-phat";
                // var firstUrlPath = @"/p27a10044/1/bai-van-khuyen-phat-tam-bo-de";

                // this works
                var kindleFile = bookHelper.CreateKindleFiles(url);
                // var fileContent = new System.IO.FileStream(kindleFile, System.IO.FileMode.Open);
                // return File(fileContent, "application/octet-stream", System.IO.Path.GetFileName(kindleFile));
            }
            else if (firstPageUri.Scheme == "file")
            {
                var note       = new MyNote();
                var bookHelper = new BookHelper(note);
                var kindleFile = bookHelper.CreateKindleFiles(url, true);
            }

            return(View("Index"));
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            var thuvienhoasen = new ThuVienHoaSen();
            //var bookHelper = new BookHelper(thuvienhoasen);

            //var firstUrlPath = @"/a15294/hieu-biet-ve-tanh-khong";
            // var output_downloadFile = @"/Users/kiettran/Downloads/Kinh_dai_bat_niet_ban.html";
            // var firstUrlPath = @"/a17221/ban-do-tu-phat";
            // var firstUrlPath = @"/p27a10044/1/bai-van-khuyen-phat-tam-bo-de";
            //var firstUrlPath = @"/p36a25595/ai-co-the-tho-gium-ai-";
            //bookHelper.CreateKindleFiles(firstUrlPath);
        }