Monday, 30 July 2012

UPLOAD AN IMAGE AND SHOW ALERT BOX if not chosen any file(upload from  in admin folder and upload image folder out of admin form)


protected void btnsubmit_Click(object sender, EventArgs e)
        {
            string filename = fileupload1.FileName;
            //string path = Server.MapPath("")+"/"+"images"+"/"+filename;

            if (txttitle.Text == null && (!fileupload1.HasFile))
            {
                string bpath = Server.MapPath("//" + "images" + "//" + filename);
                fileupload1.SaveAs(bpath);
                string imgpath = "~" + "/" + "images" + "/" + filename;
                db.Imagetitle = txttitle.Text;
                db.Imagepath = imgpath;
                db.Enteredby1 = 1;
                db.image_insert();
                txttitle.Text = null;
                ScriptManager.RegisterClientScriptBlock(btnsubmit, this.GetType(), "Salik", "alert('Image upload Successfully');", true);
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(btnsubmit, this.GetType(), "Salik", "alert(' You have not selected any file or title');", true);
            }

        }

<body>
    <form id="form1" runat="server">
    <div>
    <br />
    <center>
    <fieldset style="width:420px; height:200px">
    <legend>Upload Image</legend>
    <table style="height: 160px; width: 377px">
    <tr>
    <td colspan="2"></td>
    </tr>
    <tr>
    <td class="style1">Title</td>
    <td><asp:TextBox ID="txttitle" runat="server" Width="150px" Height="22px"></asp:TextBox></td>
    </tr>
    <tr>
    <td class="style1">Upload Image</td>
    <td>
    <asp:FileUpload ID="fileupload1" runat="server" />
    </td>
    </tr>
    <tr>
    <td class="style1"></td>
    <td>
    <asp:Button ID="btnsubmit" runat="server" Text="Submit" onclick="btnsubmit_Click" />
    </td>
    </tr>
    </table>
    </fieldset>
    </center>
    </div>
    </form>
</body>

No comments:

Post a Comment