You must Sign In to post a response.
  • Category: ASP.NET

    Page count in file upload control

    I am using file upload control of ASP.NET to upload DOC file, How can I count number of page in that uploaded DOC file ?
  • #763107

    Use ComputeStatistics method to get the no of pages in word document. If you want to know more details how to calculate the no of pages in word document I request you to please go through the below link to accomplish your task. ""

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #763111
    Hello Krunal,

    Refer the below code :

    <html xmlns="" >
    <head runat="server">
    <body style="font-family:Segoe UI;">
    <form id="form1" runat="server">
    <asp:FileUpload ID="FileUpload1" runat="server" BorderStyle="Solid" />
    <asp:Button ID="ButtonUpload" runat="server" Text="Upload" BorderStyle="Solid"
    onclick="ButtonUpload_Click" />

    Code - behind :

    protected void ButtonUpload_Click(object sender, EventArgs e)
    if (FileUpload1.HasFile)
    string fileextention = System.IO.Path.GetExtension(FileUpload1.FileName);
    if (fileextention == ".doc" || fileextention == ".docx")
    string filename = System.IO.Path.GetFileName(FileUpload1.FileName);
    FileUpload1.SaveAs(Server.MapPath("~/Docs/" + filename));
    Response.Write("Upload status: File uploaded!");

    string filepath = Server.MapPath("~/Docs/" + filename);
    if (File.Exists(filepath))
    Microsoft.Office.Interop.Word.ApplicationClass WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
    object file = filepath;

    object missing = System.Reflection.Missing.Value;

    Microsoft.Office.Interop.Word.Document aDoc = WordApp.Documents.Open(ref file, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);

    Microsoft.Office.Interop.Word.WdStatistic stat = Microsoft.Office.Interop.Word.WdStatistic.wdStatisticPages;
    int num = aDoc.ComputeStatistics(stat, ref missing);
    Response.Write("Total pages : " + num);
    Response.Write("Upload status: Only Word files are accepted!");
    catch (Exception ex)
    Response.Write("Error details: " + ex.Message);
    Response.Write("Please select a file");

    See the attached image. It's an output i have for using above mentioned code.

    Hope this is what you are looking for.

    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

    Delete Attachment

  • Sign In to post your comments