I want to render htm file to my view my code includes the uploading file function code and the convert pdf to htm code.

since my file name is variable I can't give directly path, I need to include path with the variable file name

in the end I need to display my html file to my html view

*note: my ChangePDFtoHTML Method is returning the path to the file (see 2 last code lines) but it can return other variables if needed as file name.

thanks in advance

my code:

    public ActionResult Html()
        return View();
    public ActionResult GetHtmlPage(string path)
        path = _UploadPdf();
        return new FilePathResult(path, "text/html");

    /// <summary>
    /// This Method gets pdf file file and save it on the local server
    /// </summary>
    /// <returns>html file name</returns>
    public string _UploadPdf()  
        string retFileName = "";
        //  ms_NLogger.Trace("{0} | Start", iDudi.Functions.GetIPAddress());
            for (int i = 0; i < Request.Files.Count; i++)
                var file = Request.Files[i];
                string fileName = Path.GetFileName(file.FileName);
                //string path = Path.Combine(Server.MapPath("~/userfiles/image"), fileName);
                //retFileName = fileName;

                string extension = Path.GetExtension(file.FileName);
                //string timeStamp = iDudi.Functions.GetTimestamp();
                string newName = Path.Combine(Server.MapPath("~/PDF_Files"), Path.GetFileName(file.FileName));
                retFileName = Path.GetFileNameWithoutExtension(file.FileName);
                return ChangePDFtoHTML(retFileName, extension);
        catch (Exception ex)
            //     ms_NLogger.Error("Unexpected error. ex: {0}", ex.ToString());

        //ms_NLogger.Trace("{0} | End", iDudi.Functions.GetIPAddress());

        return null;


    /// <summary>
    /// This Method convert PDF file to HTML file
    /// </summary>
    /// <param name="retFileName">file name</param>
    /// <param name="extension">file extension</param>
    /// <returns>html file</returns>
    public string ChangePDFtoHTML(string retFileName, string extension)
        string pathToPdf = Server.MapPath("~/PDF_Files/" + retFileName + extension);
        string pathToHtml = Path.ChangeExtension(Server.MapPath("~/Views/PDF_Converted_Files/" + retFileName), ".htm");
        // Convert PDF file to HTML file 
        SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();

        // force the component to store images inside HTML document 
        // using base-64 encoding 
        f.HtmlOptions.IncludeImageInHtml = true;
        //f.HtmlOptions.Title = "Simple text";


        if (f.PageCount > 0)
            int result = f.ToHtml(pathToHtml);
            //Show HTML document in browser 
            //if (result == 0)
            //    System.Diagnostics.Process.Start(pathToHtml);
        return pathToHtml;
        //return Path.GetFileName(pathToHtml);

cshtml code is showen in the link below
cshtml code here

Related posts

Recent Viewed