Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Thanks for your request. You can try using the following code:
public void Test064()
{
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
InsertImageFromURL(builder, "http://www.aspose.com/Images/aspose-logo.jpg", 250, 100);
doc.Save(@"Test064\out.doc");
}
private void InsertImageFromURL(DocumentBuilder builder, string url, double width, double height)
{
try
{
//Prepare the web page we will be asking for
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
request.ContentType = "image/JPEG";
request.UserAgent = "Mozilla/4.0+(compatible;+MSIE+5.01;+Windows+NT+5.0";
//Execute the request
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//We will read data via the response stream
Stream resStream = response.GetResponseStream();
//Write content into the MemoryStream
BinaryReader resReader = new BinaryReader(resStream);
MemoryStream imgStream = new MemoryStream(resReader.ReadBytes((int)response.ContentLength));
//Insert image into the document
builder.InsertImage(imgStream, width, height);
}
catch (WebException ex)
{
//Handle web exceptions
}
catch (Exception ex)
{
//Handle other exceptions
}
}
You can parse ex.Status. Please see the following link for more information.
http://msdn.microsoft.com/en-us/library/system.net.webexceptionstatus.aspx
Hope this helps.
Best regards.