Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My Code:

<asp:Image ID="Image1" Imageurl='<%# "\\machine-17\temp\test.jpg" %>' runat="server"/>

I tried
~,\,/ but not working...

\\machine-17\temp\test.jpg- This path come from Database(Sql Server)


Thanks In Advance
Posted
Comments
HardikPatel.SE 31-May-14 10:02am    
\\machine-17\temp\test.jpg

instead of this which path you want???

1 solution

You can write a handler that opens the file on the network and writes its contents to the response. then you can set the image url using that handler as below
ASP.NET
<asp:image runat="server" imageurl="~/NetworkImageHandler.ashx?file=file.jpg" xmlns:asp="#unknown" />

and sample handler code
C#
<![CDATA[<%@ WebHandler Language="C#" Class="Handler" %>]]>

using System.IO;

public class NetworkImageHandler : System.Web.IHttpHandler
{
  // Folder where all images are stored, process must have read access
  private const string NETWORK_SHARE = @"\\computer\share\";

  public void ProcessRequest(HttpContext context)
  {
      string fileName = context.Request.QueryString["file"];
      // Check for null or empty fileName
      // Check that this is only a file name, and not 
      // something like "../../accounting/budget.xlsx"
      // Check that the file extension is valid

      string path = Path.Combine(NETWORK_SHARE, fileName);
      // Check if the file exists

      context.Response.ContentType = "image/jpg";
      context.Response.WriteFile(path, true);
  }

  public bool IsReusable { get { return false; } }
}

Reference:
http://stackoverflow.com/a/23693948/2558060[^]
http://aspalliance.com/1322_Displaying_Images_in_ASPNET_Using_HttpHandlers.5[^]
http://bytes.com/topic/asp-net/answers/884578-image1-imageurl-not-rendering-image-when-retrieving-different-directory[^]
 
Share this answer
 
Comments
tnkarthi 2-Jun-14 0:00am    
is there any simple way???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900