Can someone provide an example of how to display all images from a specific folder in the WebImageViewer?
Hello Angela,
The WebImageViewer exposes an Items collection that can be populated with ImageItem objects (a single object represents a single image). We can manually create these objects by passing the relative image path in their constructor. We can do this for all images from a specific folder by using the built-in .NET API.
For example:
protected void Page_Load(object sender, EventArgs e) { PopulateImageViewer(); } private string[] GetFiles() { string webCurrentDirectory = HttpRuntime.AppDomainAppPath; string[] filePaths = Directory.GetFiles(webCurrentDirectory + @"\images\", "*.jpg", SearchOption.TopDirectoryOnly); string[] fileNames = filePaths.Select(filePath => Path.GetFileName(filePath)).ToArray(); return fileNames; } private void PopulateImageViewer() { string[] fileNames = GetFiles(); foreach (string fileName in fileNames) { ImageItem imageItem = new ImageItem(@"images/" + fileName, fileName, fileName + " tooltip"); imageViewer.Items.Add(imageItem); } }
Please note that the above code is just a single approach that can be used and in order to work with extensions other than .jpg, we can simply use the Directory.GetFiles method again by changing the searchPattern argument.
I have attached a sample application that demonstrates the mentioned approach.
If you have any questions, please let me know.
5758.WebImageViewer_sample.zip
Is there any way you can provide the same in vb?
I have attached a project that introduces the same approach as in my previous reply by using VB on the server-side.
7711.WebSite2.zip