Category: ASP.NET

Web.config AppSettings

Global variables can be set in web.config. In general, these are variables that are not frequently changed. For example, the mail server. A key can be added in the section. <configuration><appSettings>    <add key=”MyMailServer” value=”mymailserver.com” /></appSettings></configuration> Then the value can be retrieved in the code Dim MyMailServer as String = ConfigurationManager.AppSettings(“MyMailServer”)

Read a text file in ASP.NET

The System.IO namespace contains the StreamReader class allow reading of files. You can then read the entire contents of the text file into a string, by using ReadToEnd() method. Remmber to close the StreamReader using the Close() method when finished.  <!DOCTYPE html><script runat=”server”>    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles […]

Create a text file in ASP.NET

We need the namespace, System.IO to use files. The method, CreateText requires a string for an argument. The string is the path of file which will be created. After we have correctly written to the text file, we close the StreamWriter by invoking the Close method of StreamWriter. See below for example code. <!DOCTYPE html><script […]

ASP Panel v ASP Placeholder

I always get the feeling that there is not much difference between the asp:panel and asp:placeholder server controls in ASP.NET. The Panel control is useful for grouping together other controls or HTML segments. The control can be thought of as the server side equivalent of the <div> tag. The PlaceHolder control can also be used […]

Create a Virtual Directory

I always have a local copy of websites that I work on. Some people like to put the folders inside of the inetpub/wwwroot folder. But, I tend to put my website into a folder c:\websites and then create virtual directories. The following methods should work fine for WinXP and Win2000. To create a virtual directory […]

Add text to Image in ASP.NET

Sometimes, it is nice to have a text caption embedded into an image, rather than display the caption in HTML. Fortunately, this is fairly straightforward in ASP.NET. You can embed some text into the photo: /image_text.aspx?i=/photo.jpg&t=Photo+of+You Play around with the querystring. See how the caption changes when you change the text in the querystring. Here […]