Hi All,
I have an image tag and a fileuploader to upload file.It works fine .Sometimes the user need to change the already uploaded file.It also works fine .But the problem is that even after uploading new image ,it is saved ,but the earlier image is still showing on image tag and is not refreshed.Any help will be really appreciated .Thanks in Advance.
What I have tried:
<tr>
<td align="left">Choose file </td>
<td style="padding-left:5px; padding-right:5px;">:</td>
<td align="left">
<asp:FileUpload ID="FileUpload1" runat="server" class="txtboxAll" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center">
<asp:Button ID="but_uploadfile" runat="server" ValidationGroup="First" TabIndex="16"
CssClass="btnAll" Text="Upload" onclick="but_uploadfile_Click" />
<asp:Button ID="btn_Close01" runat="server" ValidationGroup="First" TabIndex="17"
CssClass="btnAll" Text="Close" />
</td>
</tr>
protected void but_uploadfile_Click(object sender, EventArgs e)
{
queryusrid = Request.QueryString["cid"].ToString();
string oldfilename1 = Path.GetFileName(FileUpload1.FileName);
System.Drawing.Image img = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream);
int height = img.Height;
int width = img.Width;
if (oldfilename1 == "")
{
Alert.Show("Please select a file to upload");
return;
}
else
{
string gid2 = lbl_gid.Text;
string ext = Path.GetExtension(FileUpload1.FileName);
if (ext == ".jpg" || ext == ".JPG" || ext == ".jpeg" || ext == ".JPEG")
{
if (width == 200 && height == 230)
{
string FileExist = objcon.GetDataReadervalue("select IN005_01_01 from IN005_01 where IN005_01='" + gid2 + "' and IN005_01_07='photo'", "value");
if (FileExist == "Not Found")
{
string serpath1 = Server.MapPath("~/Registeration/ProfilePics/");
string newfileid1 = GenerateFileID();
FileUpload1.SaveAs(serpath1 + newfileid1 + ext);
string newfileid4 = newfileid1 + ext;
bool ret3 = objcon.Modify("insert into IN005_01(IN005_01_01,IN005_01_02,IN005_01_03,IN005_01_06,IN005_01_07,IN005_01)Values('" + newfileid1 + "','" + newfileid4 + "','" + oldfilename1 + "','sumhr','photo','" + gid2 + "')");
DataList1.DataBind();
UpdatePanel7.Update();
}
else
{
string filename = objcon.GetDataReadervalue("select IN005_01_02 from IN005_01 where IN005_01='" + gid2 + "' and IN005_01_07='photo'", "value");
string filenameetn = objcon.GetDataReadervalue("select IN005_01_01 from IN005_01 where IN005_01='" + gid2 + "' and IN005_01_07='photo'", "value");
string path = Server.MapPath("~") + "\\Registeration" + "\\ProfilePics" + "\\" + filename;
if (System.IO.File.Exists(path))
{
System.IO.File.Delete(path);
string serpath1 = Server.MapPath("~/Registeration/ProfilePics/");
string newfileid1 = filenameetn;
FileUpload1.SaveAs(serpath1 + newfileid1 + ext);
string newfileid4 = newfileid1 + ext;
bool ret3 = objcon.Modify("update IN005_01 set IN005_01_02='" + newfileid4 + "',IN005_01_03='" + oldfilename1 + "',IN005_01_06='auto' where IN005_01_01='" + filenameetn + "'");
DataList1.DataBind();
UpdatePanel7.Update();
}
}
}
else
{
Alert.Show("Image size should Width*Height-(200*230px)");
return;
}
}
else
{
Alert.Show("Please upload any jpg,png,jpeg files");
return;
}
}
}