I have used Google static map and created linked resource and embedded it in email and sending the mail to all users. I send a request to Google server and convert the response as stream and then created linked resource using that stream. The problem is I have used for loop and sent mail to all emailid's present in the Database table, i have created linked resource being created inside the for loop so each time the same image is requested from the Google server and mailed to user's. I want to prevent this, only for the first time the request has to be sent to Google and i have to store that response stream and use it to create linked resource. How to do this? i have tried storing the stream in local stream variable and created linked resource using that stream variable, i have also stored the stream in viewstate as well as in session but none of the methods worked out!
for (iCnt = 0; iCnt < dsEmailIds.Tables[0].Rows.Count; iCnt++) { //Linked resource to embed Google map in mail LinkedResource lnkResMain; if (imgPhotos.Src.Contains("maps.google.com")) lnkResMain = new LinkedResource(getStream(imgPhotos.Src));
//send mail mail.SendMail(fromAddress,dsEmailIds.Tables[0].Rows[0]["toAddress"].ToString(),lnkResMain);
}
//this converts string image url to stream since stream can be used to create linked resource public Stream getStream(string imgUrl) { System.Net.WebRequest req = System.Net.WebRequest.Create(imgUrl); System.Net.WebResponse response = req.GetResponse(); Stream stream = response.GetResponseStream(); return stream; }