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
    Hi,

    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. "codeproject.com/Articles/4041/Count-pages-in-MS-Word-Document"

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

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #763111
    Hello Krunal,

    Refer the below code :

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title></title>
    </head>
    <body style="font-family:Segoe UI;">
    <form id="form1" runat="server">
    <div>
    <asp:FileUpload ID="FileUpload1" runat="server" BorderStyle="Solid" />
    <asp:Button ID="ButtonUpload" runat="server" Text="Upload" BorderStyle="Solid"
    onclick="ButtonUpload_Click" />
    </div>
    </form>
    </body>
    </html>


    Code - behind :

    protected void ButtonUpload_Click(object sender, EventArgs e)
    {
    if (FileUpload1.HasFile)
    {
    try
    {
    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);
    }
    }
    else
    Response.Write("Upload status: Only Word files are accepted!");
    }
    catch (Exception ex)
    {
    Response.Write("Error details: " + ex.Message);
    }
    }
    else
    {
    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.

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

    Delete Attachment


Sign In to post your comments