Unable to download image in user side downloads folder . i have tried a number of ways to solve the problem.I have also given the file path of user and trying to download image presented in asp:image control "url" ... Whole code executed but didn't saved image in folder.I have tries more solution but didn't worked.any suggestions to help me out... i am stuck at this..thank you in advance...
//To show image from URl on asp:image control on click of gridview button
protected void Redirect1_Click(object sender, EventArgs e)
{
var rowIndex = ((GridViewRow)((Control)sender).NamingContainer).RowIndex;
BookingNO = GridView1.Rows[rowIndex].Cells[0].Text;
var request = WebRequest.Create("http:-#-//?a=" + BookingNO + "&b=2" + "");
using (var response = request.GetResponse())
using (var stream = response.GetResponseStream())
{
LoadImage.ImageUrl = "http:-#-//?a=" + BookingNO + "&b=2" + "";
LoadImage.Visible = true;
md.Visible = true;
LoadImage.ToolTip = "Image of Order Number. " + BookingNO + "";
Download.Visible = true;
}
}
//Button Click to download image of
public void Download_click(object sender, EventArgs e)
{
try
{
string pathUser = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
string pathDownload = Path.Combine(pathUser, "Downloads");
string url = LoadImage.ImageUrl;
byte[] data;
using (WebClient client = new WebClient())
{
data = client.DownloadData(url);
}
File.WriteAllBytes(pathDownload + BookingNO + ".jpg", data);
ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Order Number " + BookingNO + " Image Saved');", true);
}
catch (Exception ex)
{
}
}