1) First we have to create the folders Content\profilepic
in web.config file
<configuration>
<appSettings>
<add key="propicpath" value="cms\Content\profilepic\"/>
</appSettings>
<configuration>
aspx code
<asp:Label ID="image" runat="server"></asp:Label>
aspx.cs code
To view the image:-
image.Text = "<img src='" + ConfigurationManager.AppSettings["propicpath"] + "" + dtp.Rows[0]["profile_pic"].ToString() + "' alt='Improper format' height='132px' width='102px'/>";
To save the image:-
protected void btn_update_Click(object sender, EventArgs e)
{
if (fu_image.HasFile || image.Text != "")
{
if (fu_image.HasFile)
{
string strpath = System.IO.Path.GetExtension(fu_image.FileName);
Filename = FMSID + "_photo" + strpath;
if (strpath != ".jpeg" && strpath != ".JPEG" && strpath != ".PNG" && strpath != ".png" && strpath != ".JPG" && strpath != ".jpg")
{
Response.Write("<script>alert('Please upload valid photo')</script>");
}
else
{
HttpPostedFile hpf = fu_image.PostedFile;
int photo_file_size = hpf.ContentLength;
if (photo_file_size > 20 * 1024 && photo_file_size < 100 * 1024)
{
string dirUrl = ConfigurationManager.AppSettings["propicpath"];
string dirPath = Server.MapPath(dirUrl);
if (!Directory.Exists(dirPath))
{
Directory.CreateDirectory(dirPath);
}
string filePath = ConfigurationManager.AppSettings["propicpath"] + Filename;
fu_image.SaveAs(Server.MapPath(filePath));
updateinfo();
}
else
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Photo must be 20 to 100kb')", true);
}
}
}
else
{
Filename = imagename.Text;
updateinfo();
}
}
else
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Photo is important')", true);
}
}
No comments:
Post a Comment