Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

What is the syntax for ImageURL from another in-house server?

What is the syntax for ImageURL from another in-house server?

What is the syntax for ImageURL from another in-house server?

This does not seem like it should be that hard, but for some reason I'm stuck.

We have a file server that houses images from several applications and our web server needs to display them. When I add this code, I get a broken image icon.


<asp:Image ID="imgPhoto" runat="server" Width="140px"
    ImageUrl="\\SERVERNAME\FolderName\44959\Graphic.jpg" /> 

Nothing is being uploaded, so no virtual path is necessary.

The code is on the development PC which is in the same domain as the web server. Am I missing something obvious?


RE: What is the syntax for ImageURL from another in-house server?

We do the same thing. But what you have to do is a set up a web that can serve up the images to your website. So you would have to access an image on the server something like:


RE: What is the syntax for ImageURL from another in-house server?

Thanks jbenson001. What you said makes perfect sense, but I couldn't make it happen. It turns out what I thought was just a file server for the images does more than that so they won't let me touch IIS there.

Here's the approach I took. Hopefully someone can use it.

As you said, it has to be a URL, so I made it one by creating ImageViewer.aspx which only has a DIV.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <form id="form1" runat="server">

Then I added this to the code behind:

CODE --> C#

protected void Page_Load(object sender, System.EventArgs e)
    if (Request.QueryString("sFileName") + "" > "") {
        try {
            // Read the file and convert it to Byte Array
            string sFileName = Request.QueryString("sFileName");
            string sDirectory = Request.QueryString("sDirectory");

            // SourcePath is from web.config in the format of \\ServerName\Folder1\Folder
            // In my code, sDirectory is dynamically built, but I've modified it here to act
            // like it's passed in in the QueryString.
            string sFilePath = Path.Combine(ConfigurationManager.AppSettings.Item("SourcePath"), sDirectory);

            // Used for generating the image in the viewer.
            string sContentType = "image/" + Path.GetExtension(sFileName).Replace(".", "");

            FileStream fs = new FileStream(sFilePath + sFileName, FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(fs);
            byte[] bytes = br.ReadBytes(Convert.ToInt32(fs.Length));


            //Write the file to Reponse
            Response.Buffer = true;
            Response.Charset = "";
            Response.ContentType = sContentType;
            Response.AddHeader("content-disposition", "attachment;filename=" + sFileName);
        } catch (Exception ex) {
            throw ex;

Now I am able to use the following as the image tag:


<asp:Image runat='server' ID='imgFile' ImageUrl="./ImageViewer.aspx?sFileName=317179.jpg&sDirectory=ImageFolder\"
                        AlternateText='' Width='115px' ToolTip="317179.jpg" /> 

RE: What is the syntax for ImageURL from another in-house server?

Good idea. You can take this one step further by using a handler (.ashx). It is a page without the UI. So you have all the same coding abilities without the extra overhead of a UI, which, in your case, you don't need. Take a look into it. It's a good thing to know, and we use it often, especially in the case of getting images from our image server.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close