Well! I think I have framed solution but need your
confirmation for same.
Understanding Requirement
I have server X with IP address as
223.176.59.170 and website hosted on it with name as
ImageHub with
SelectImage.aspx as home page of website. In the same website we have stored two images in folder named
Images. Now as per our requirement we want to use the following url
http://223.176.59.170/ImageHub/SelectImage.aspx?ImageID=4
for returning image in Aspose document.
Solution for requirement
Here is the code for returning image as response to caller. We have used ContentType for gif type only. However you can use switch case for modifying same based on file type.
(Code snippet from SelectImage.aspx.cs):
public partial class _Default : System.Web.UI.Page
{
string imageUrl;
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["ImageID"] != null)
{
string imageId = Request.QueryString["ImageID"].ToString();
// Set imageUrl
switch (imageId)
{
case "8":
imageUrl = VirtualPathUtility.ToAbsolute("~") + @"/Images/save.gif";
break;
case "4":
imageUrl = VirtualPathUtility.ToAbsolute("~") + @"/Images/register.png";
break;
}
// Check if file exists and set headers appropriately
// Return response directly to output steam
System.IO.FileInfo file = new System.IO.FileInfo(Server.MapPath(imageUrl));
if (file.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", @"inline; filename=\" + file.Name);
Response.AddHeader("Content-Length", file.Length.ToString());
// Put switch..case for modifying ContentType on basis of file extension
// I have written code for gif type
Response.ContentType = "image/gif";
Response.TransmitFile(file.FullName);
Response.End();
}
}
}
}
And in the code part of DocBuilder we have modified the imagePath as:
(You can use website name rthfjkl002 in place of the IP address)
string imagePath = @"http://223.176.59.170/ImageHub/SelectImage.aspx?ImageID=8";
That's all! Test it and let us know.