Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
77 views2 pages

Miscellaneous

The document provides code samples to display a random image from a directory on a web page in VB.NET and C#. It gets a random file from the directory, constructs the image path, and sets the background attribute of a table cell to display the random image.

Uploaded by

api-3841500
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views2 pages

Miscellaneous

The document provides code samples to display a random image from a directory on a web page in VB.NET and C#. It gets a random file from the directory, constructs the image path, and sets the background attribute of a table cell to display the random image.

Uploaded by

api-3841500
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

The .

aspx pages are the only ones that support the Src attribute, and therefore it's the only file type that

supports JIT compilation of separate source files.By using the Src attribute in the page directive, you can

specify which file the ASP.NET engine should compile.

It cannot be used with a WebService.

This means that you must precompile the code behind class that is to be used as the basis for the Web

Service, either manually using the Command-line compiler or by building a Visual Studio.NET Web Service

Application.

4.51 How to display random images on a web page from a set of images
in a directory?

<table id="Table1" cellspacing="1" cellpadding="1" border="1">


<tr>
<td id="TD1" width="100" runat="server">

</td>
</tr>
</table>

VB.NET (Add reference to Microsoft Visual Basic .NET Runtime)

Dim dirInfo As New System.IO.DirectoryInfo("c:\inetpub\wwwroot\syncfusion\images") 'This is your path to


the bmp's
Dim fileInfo() As IO.FileInfo
Dim strRandomImage As String
Dim i As Integer
Dim rnd As Random
fileInfo = dirInfo.GetFiles("*") 'Gets an array of file info
rnd = New Random
Randomize()
i = CInt(rnd.NextDouble * UBound(fileInfo)) ' gets a random index
strRandomImage = "images/" + fileInfo(i).Name ' Returns the random string
TD1.Attributes.Add("background", strRandomImage)

C#

System.IO.DirectoryInfo dirInfo =new


System.IO.DirectoryInfo(@"c:\inetpub\wwwroot\SyncnewCsharp\images") ;//This is your path to the bmp's
System.IO.FileInfo[] fileInfo ;
string strRandomImage;
int i ;
Random rnd ;
fileInfo = dirInfo.GetFiles("*"); //Gets an array of file info
rnd = new Random();
Microsoft.VisualBasic.VBMath.Randomize ();
i = Convert.ToInt32 (rnd.NextDouble() * fileInfo.GetUpperBound(0));// gets a random index
strRandomImage = "Images/" + fileInfo[i].Name ;// Returns the random string
TD1.Attributes.Add ("background", strRandomImage);

4.52 How can I scan a string to determine if it contains DBCS chars?

You might also like