c# - To bind images in repeater using asp.net -


I have a criminal in the code below and I want to force the images to be replicated by local drive. But the image is not binding, but I can get the image name from local drive pls to solve this problem.

  string [] filePaths = Directory.GetFiles ("D: \\ user \\ images \\ pictures \\"); & Lt; ListItem & gt; Files = New list & lt; ListItem & gt; (); Foreach (string filePaths in filePaths) {string fileName = Path. GetFileName (filePath); Files.Add (New ListItem (fileName, @ "D: \ Users \ Images \ Pictures \" + fileName)); // I can get image name - D: \ user \ images \ picture \ flight.jpg} repeat1 Data source = files; Repeater1.DataBind (); & Lt; Asp: repeater id = "repeater 1" runat = "server" & gt; & Lt; ItemTemplate & gt; & Lt; Li & gt; & Lt; Img src = '& lt;% # DataBinder.Eval (container.datetime, "value")% & gt; Title = '& lt;% # (DataBinder.Eval (container.datetime, "text"). Toasting ()). Split ('.') [0]. Ostring ()%> Alt = "" & gt; & Lt; / Li & gt; & Lt; / ItemTemplate & gt; & Lt; / ASP: Repeater & gt;  

The client can not download a file outside the Web application's folder. You have two options -

Option 1

Insert images inside the web application. For example,

enter image details here

options 2

Make a generic handler.

Note: When your application runs in production, you will need to make sure that D: \ user \ image Folder is present in the web server

  public class ImageHandler: IHttpHandler {public void ProcessRequest {HttpContext reference} {string fileName = context.Request.QueryString ["filename"]; Context.Response.ContentType = "image / jpeg"; Context.Response.TransmitFile (@ "D: \ User Images \ Picture \" + Filename); } Public Child IRUBL ({return wrong;}}} ASPX and lieutenant; ASP: repeater id = "repeater 1" runat = "server"> gt; item title & gt; & lt; asp: image runat = "server "ImageUrl = '& lt;% #' ~ / ImageHandler.ashx? Filename =" + EVAL ("value")%> '/ & gt; & lt; / ItemTemplate & gt; & lt; / ASP: repeater & Gt; Secure Zero Page_load (Object Sender, EventRargs E) {if (IsPostBack) {string [] filePaths = Directory.GetFiles (@ "D: \ User \ Picture \ Picture"); List & gt; ListItem & gt; ; Files = New list & lt; ListItem & gt; (); Foreach (in filePaths String filePath) {string fileName = path.GetFileName (FilesPath); Files.Add (New ListItem (fileName, fileName))}} Repeater 1. Data Source = Files; Repeater1.DataBind ();}}  < / Pre> 

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -