Show epub book in browser from Folder (Directory) in ASP.Net using C# and VB.Net

on Jun 23, 2022 12:02 AM

It's not reading from local server path

<script type="text/javascript">
    window.onload = function () {


 protected void Page_Load(object sender, EventArgs e)
    if (!IsPostBack)
        string path = Server.MapPath("~/Books/Documents/25707spiderspider.epub");

public StringBuilder epubPath = new StringBuilder();
Download FREE API for Word, Excel and PDF in ASP.Net: Download
on Jun 23, 2022 03:10 AM

Hi mukesh1,

You need to convert the url to AbsoluteUri.

Then set the path in a property and use that in the JavaScript.

Refer below sample.


<div id="main">
    <div id="titlebar">
        <div id="metainfo">
            <span id="book-title"></span>
            <span id="title-seperator">&nbsp;&nbsp;–&nbsp;&nbsp;</span>
            <span id="chapter-title"></span>
    <div id="divider"></div>
    <div id="prev" class="arrow">‹</div>
    <div id="viewer"></div>
    <div id="next" class="arrow">›</div>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src="/Scripts/epub.js"></script>
<script type="text/javascript" src="/Scripts/reader.js"></script>
<link rel="stylesheet" href="CSS/main.css">
<script type="text/javascript">
    window.onload = function () {



protected string epubPath { get; set; }
protected void Page_Load(object sender, EventArgs e)
    epubPath = GetUrl("alice.epub");

protected string GetUrl(string filePath)
    string[] splits = Request.Url.AbsoluteUri.Split('/');
    if (splits.Length >= 2)
        string url = splits[0] + "//";
        for (int i = 2; i < splits.Length - 1; i++)
            url += splits[i];
            url += "/";
        return url + filePath;
    return filePath;


Protected Property epubPath As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    epubPath = GetUrl("alice.epub")
End Sub

Protected Function GetUrl(ByVal filePath As String) As String
    Dim splits As String() = Request.Url.AbsoluteUri.Split("/"c)
    If splits.Length >= 2 Then
        Dim url As String = splits(0) & "//"
        For i As Integer = 2 To splits.Length - 1 - 1
            url += splits(i)
            url += "/"
        Return url & filePath
    End If
    Return filePath
End Function

You need to add the mime type th the web config inside the system.webServer section.

    <mimeMap fileExtension=".epub" mimeType="application/octet-stream" />