Trying to use jquery and lightbox against a image directory on our webserver. I have lightbox working with hardcoded images just fine. I have found some instruction for using a folder but it uses php to scan the folder. Tried to use the old php to asp.net
migration tool but can't get it to install. I am using VS 2012. Below is the code for php, which I don't understand so I'm noy sure how to re-code in vb. Can any help me out?
$directory
= 'gallery'; //where the gallery images are located
Went about a slightly different way in the end but it produces what I need. The datalist then feeds lightbox
'select random number of files from imageNames
Dim imagePaths() As String = Directory.GetFiles(Server.MapPath("Images/Burning"))
Dim imageNames As New List(Of String)
For Each Path As String In imagePaths
imageNames.Add(Path.Substring(Path.LastIndexOf("\") + 1))
Next
Static R As New Random
While imageNames.Count > 6
imageNames.RemoveAt(R.Next(imageNames.Count))
End While
Dim dt = New DataTable()
dt.Columns.Add("ImageName", GetType(String))
dt.Columns.Add("ImagePath", GetType(String))
For Each imgName In imageNames
Dim dr As DataRow = dt.NewRow()
dr("ImageName") = RemoveExtension(imgName)
dr("ImagePath") = "Images/Burning/" & imgName
dt.Rows.Add(dr)
Next
DataList1.DataSource = dt
DataList1.DataBind()
Marked as answer by bicosteel on Jan 30, 2013 12:48 PM
bicosteel
Member
12 Points
33 Posts
I need help converting php to asp.net 4/vb.net
Jan 24, 2013 06:55 PM|LINK
Trying to use jquery and lightbox against a image directory on our webserver. I have lightbox working with hardcoded images just fine. I have found some instruction for using a folder but it uses php to scan the folder. Tried to use the old php to asp.net migration tool but can't get it to install. I am using VS 2012. Below is the code for php, which I don't understand so I'm noy sure how to re-code in vb. Can any help me out?
$directory='gallery';//where the gallery images are located$allowed_types=array('jpg','jpeg','gif','png');//allowed image types$file_parts=array();$ext='';$title='';$i=0;//try to open the directory$dir_handle= @opendir($directory)ordie("There is an error with your image directory!");while($file= readdir($dir_handle))//traverse through the files{if($file=='.'||$file=='..')continue;//skip links to the current and parent directories$file_parts=explode('.',$file);//split the file name and put each part in an array$ext=strtolower(array_pop($file_parts));//the last element is the extension$title= implode('.',$file_parts);//once the extension has been popped out, all that is left is the file name$title= htmlspecialchars($title);//make the filename html-safe to prevent potential security issues$nomargin='';if(in_array($ext,$allowed_types))//if the extension is an allowable type{if(($i+1)%4==0)$nomargin='nomargin';//the last image on the row is assigned the CSS class "nomargin"echo'<divclass="pic '.$nomargin.'"style="background:url('.$directory.'/'.$file.') no-repeat 50% 50%;"><a href="'.$directory.'/'.$file.'"title="'.$title.'"target="_blank">'.$title.'</a></div>';$i++;//increment the image counter}}closedir($dir_handle);//close the directorybicosteel
Member
12 Points
33 Posts
Re: I need help converting php to asp.net 4/vb.net
Jan 30, 2013 12:48 PM|LINK
Went about a slightly different way in the end but it produces what I need. The datalist then feeds lightbox 'select random number of files from imageNames Dim imagePaths() As String = Directory.GetFiles(Server.MapPath("Images/Burning")) Dim imageNames As New List(Of String) For Each Path As String In imagePaths imageNames.Add(Path.Substring(Path.LastIndexOf("\") + 1)) Next Static R As New Random While imageNames.Count > 6 imageNames.RemoveAt(R.Next(imageNames.Count)) End While Dim dt = New DataTable() dt.Columns.Add("ImageName", GetType(String)) dt.Columns.Add("ImagePath", GetType(String)) For Each imgName In imageNames Dim dr As DataRow = dt.NewRow() dr("ImageName") = RemoveExtension(imgName) dr("ImagePath") = "Images/Burning/" & imgName dt.Rows.Add(dr) Next DataList1.DataSource = dt DataList1.DataBind()