How to get the Computer Name on which the code is running
This will return the information of the server computer, not the client browser computer. Add reference to System.Windows.Forms.dll. VB.NET Response.Write(System.Windows.Forms.SystemInformation.ComputerName) C# Response.Write(System.Windows.Forms.SystemInformation.ComputerName);
How to compile CS/VB file and place new DLL in bin subdirectory
You can build a dll using the following command line . Assuming your command window has the appropriate path set to use the following exes: VB.NET compiler vbc.exe vbc.exe /out:SyncVB.dll /target:library SyncVB.vb C# compiler csc.exe csc.exe /out:SyncCS.dll /target:library SyncCS.cs To reference it within the .aspx page use the Import directive: <%@ Import Namespace=’SyncVB’ %> or <%@ Import Namespace=’SyncCS’ %>
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);
How to know the width and height in pixels of a given image programmatically
You will have to create a Bitmap instance from the image file and then query the Width and Height as follows: VB.NET Dim bm As Bitmap = New Bitmap(Server.MapPath(‘b2346.jpg’)) Response.Write(‘Height :’ + bm.Height.ToString()) Response.Write(‘<br> Width :’ + bm.Width.ToString()) C# Bitmap bm = new Bitmap( Server.MapPath(‘b2346.jpg’)); Response.Write (‘Height :’ + bm.Height.ToString() ); Response.Write (‘<br> Width :’ +bm.Width.ToString() );
Request.ServerVariables(‘LOGON_USER’) always returns empty string in Framework 1.1 . Why? It worked fine in ASP
If Request.ServerVariables(‘LOGON_USER’) is returning an empty string, the problem is probably that your app allows anonymous users. To change this: Open IIS manager right-click on your app name and choose properties Click on directory security tab Edit Authentication and Access Control Uncheck ’Enable anonymous’.