Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello Guys i am validating a pdf file that is working fine.. now i am trying to
validate a pdf file with id..our reQuirement is we are uploading a file 
when some conditions are true..

example if the person has an id den only he can upload..

now i need to validate the pdf file with id..filename should have certain parametres
like id that can be validated..


protected void btnSubmit_Click(object sender, EventArgs e)
        {

 var flag = false;
            try
            {

 if (fileUpload.HasFile )
                {

 var extension = System.IO.Path.GetExtension(fileUpload.FileName);
 if (extension.ToLower() == ".pdf")
                    {
 using (var conn = new SqlConnection(dbString))
                        {

                 line of code
                 }
       }
else
{
label.Text = "Please upload pdf files..";
}

}
else
                {

 if (!fileUpload.HasFile)
                    {
                        label.Text = "Please upload the file..";
               }
}
     }

catch(exception ex)
{
  lblStatus.Text = ex.Message;= ex.Message;
}


What I have tried:

validating pdf file works fine..
but how do i now pass a id as a paramtere that can be validated
Posted
Updated 6-Jul-17 2:58am
Comments
Sheila Pontes 6-Jul-17 8:13am    
Hi,

Do you have a input where the person type the id?
Mahesh2223 11-Jul-17 1:54am    
Yes i have a input where he types id
Sheila Pontes 11-Jul-17 8:05am    
Mahesh, hi

See the solution below that i wrote to you. See if it solves your problem.
Mahesh2223 12-Jul-17 10:59am    
yes sure i wil try it and let u know

1 solution

Hi,

To solve your problem, I ask the person, the ID first and validate this id in the database. If this id is valid, I open the option to upload the pdf file.
After uploading, I only validate the file because the id is valid.

Below example.

HTML code

ASP.NET
<pre><form id="form1" runat="server">
    <div>
        <label>Type your id:</label>
        <asp:TextBox ID="txtId" runat="server"></asp:TextBox>
        <asp:Button ID="btn_validate" runat="server" Text="Validate" OnClick="btn_validate_Click" />
    </div>
    <br />
    <div id="upload" runat="server" visible="false">
        <asp:FileUpload ID="my_file_upload" runat="server" />
    </div>
        <asp:Label ID="lblStatus" runat="server" Text="Label"></asp:Label>
    </form>



code-behind

C#
public partial class frmMyTest2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        private bool validate_id()
        {
            //connection in your data base e validate in your table.
            //Example:
            //select id from mytable_id where id=" + this.txtId.Text.Trim(); 
            //if the select return 1 line is true else false;

            return true;
        }

        protected void btn_validate_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.validate_id())
                {
                    this.upload.Visible = true;
                }
                else
                {
                    this.lblStatus.Text = "This id is not valid";
                }
            }
            catch (Exception ex)
            {
                lblStatus.Text = ex.Message;
            }
        }
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900