English 中文(简体)
如何从图像夹中储存图像,然后将其传送到图像弧中(asp.net .pdfb.net)
原标题:How to store images in a list from image folder and passing it to image src in (asp.net| vb.net)

I have got two image folders namely a and b which consist of images of products. All images are save as there productid. how can can i find the images from a folder by passing there productid and save the images in a list.

Dim AllImages As New List(Of String)

After saving it , how can i render those images one by one into string builder like

Dim imagecontainer As New StringBuilder
 For Each image In AllImages
imagecontainer.Append("<img src="image" alt="" />") Next image

Any ideas of how to do this, your help will be highly appreciated.
最佳回答

You can use the ResolveClientUrl within your page code-behind:


var clientImageUrl = ResolveClientUrl("yourimagefolder/sampleimage.jpg");

或者,你可以使用虚拟卫生。 2. 巩固这一结果:


VirtualPathUtility.ToAbsolute("yourimagefolder/sampleimage.jpg")

In order to read all the files from a folder and then filter them by file name (your ID) you can use (use the System.IO namespace) :


 DirectoryInfo directory = new System.IO.DirectoryInfo("c:YourFolder");
 var allFiles = directory.GetFiles(".", System.IO.SearchOption.AllDirectories);
var fileFounds = from file in allFiles where file.Name == "YourID" select file;

foreach (var file in fileFounds) { //Build your image }

EDIT: here s the vb.net version (I ve used a code converter, hope it worked well: )


 Using ResolveClientUrl 
Dim clientImageUrl = ResolveClientUrl("yourimagefolder/sampleimage.jpg")

Using VirtualPathUtility VirtualPathUtility.ToAbsolute("yourimagefolder/sampleimage.jpg")

Reading files from directory Dim directory As DirectoryInfo = New System.IO.DirectoryInfo("c:YourFolder") Dim allFiles = directory.GetFiles(".", System.IO.SearchOption.AllDirectories)

Dim fileFounds = _ Where file.Name = "YourID"

     Build your image

For Each file As var In fileFounds Next

问题回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签