I have image upload functionality in which the uploaded image should be saved into a system folder. The uploaded image should also get displayed in the page, to get the image from the system folder I have used the help of an ashx and the image is getting loaded correctly at the time of page load. Now I want to dynamically get the image on gdvPartner_SelectedIndexChanged. Please help.
What I have tried:
<tr align="center" style="height:40">
<td class="FormLabels" align="right" style="vertical-align: top">Upload Logo : </td>
<td align="Left" style="vertical-align: top;width: 30%;padding:5px" colspan="2">
<telerik:RadAsyncUpload ID="flUpload" runat="server" MaxFileInputsCount="1" AllowedFileExtensions=".png"
Skin="Web20" Width="200px" />
<asp:Button ID="btnUpload" runat="server" Style="text-decoration: none; border-radius: 5px;
border: solid 1px #f39c12;" Text="Upload" CssClass="submitButton" SkinID="Submit"
OnClick="btnUpload_Click" />
</td>
<td align="Left" colspan="2" style="height: 180px;width: 35%;padding-left:10px">
<asp:Image Width="200px" Height="150px" runat="server" ImageUrl="../UserControl/GetImage.ashx"
ID="imgSelectedPhoto" />
</td>
</tr>
protected void btnUpload_Click(object sender, EventArgs e)
{
if (flUpload.UploadedFiles.Count != 0)
{
SaveAsThumbNail();
}
}
private void SaveAsThumbNail()
{
Common cmnObj = new Common();
try
{
string serPath = Utilities.DecryptString(cmnObj.RetriveKeyFromSettingsTable("PartnerLogoPath"));
string newFileName = SessionHandler.TempPartnerId;
newFileName = newFileName + "." + ImageFormat.Png.ToString();
string imgPath = serPath + "/" + newFileName;
flUpload.UploadedFiles[0].SaveAs(imgPath);
}
catch (Exception ex)
{
BasePage bp = new BasePage();
bp.GetErrorMessage("", "", ex, Page.Title, "SaveAsThumbNail");
}
}
public void ProcessRequest(HttpContext context)
{
string imgPath = string.Empty;
string extension = string.Empty;
Common cmnObj = new Common();
string serPath = Utilities.DecryptString(cmnObj.RetriveKeyFromSettingsTable("PartnerLogoPath"));
string newFileName = SessionHandler.TempPartnerId;
newFileName = newFileName + "." + ImageFormat.Png.ToString();
imgPath = serPath + "/" + newFileName;
if (File.Exists(imgPath))
{
string contentType = string.Empty;
imgPath = Convert.ToString(imgPath);
extension = imgPath.Substring((imgPath.Length - 4), 4).ToLower();
switch (extension)
{
case ".png":
contentType = "image/png";
break;
default:
break;
}
context.Response.ContentType = contentType;
context.Response.TransmitFile(imgPath);
}
else
{
context.Response.TransmitFile("~/Images/NoImage.gif");
}
}
protected void gdvPartner_SelectedIndexChanged(object sender, EventArgs e)
{
string siteHandlerUrl = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + ResolveUrl("~/") + "UserControl/GetImage.ashx";
imgSelectedPhoto.ImageUrl = Page.ResolveUrl(siteHandlerUrl);
}