using: c# , .net
i want use try catch display image of product in new window window. works unless image not exist meaning (http error 404 - file or directory not found) page. if happens button nothing when clicked.
what want happen when click button , file not exist user taken "image not exist" page. have tried in following code. not work. advice!
bool imageexists = true; try { webresponse = webrequest.getresponse(); } catch { imageexists = false; } if (imageexists == true) { clientscript.registerstartupscript(this.gettype(), "openfoundimage", "window.open('" + pathtofolder + "');", true); } else { system.diagnostics.process.start("http://www.companysite.com/noimage.jpg"); }
edit: changed bool.
try catch won't trigger in this. see link below
how to: request data using webrequest class
4.. can access properties of webresponse or cast webresponse protocol-specific instance read protocol-specific properties. example, access http-specific properties of httpwebresponse, cast webresponse httpwebresponse reference. following code example shows how display status information sent response.
console.writeline (((httpwebresponse)response).statusdescription);
add logic around status return.
Comments
Post a Comment