Count the Number of files in a Directory using asp.net

Count the Number of specified files in a Directory

Below is a function 'FilesDirectoryCount' that will count the number of files within a directory using The .NET Framework class Directory. The GetFiles method allows us to retrieve all the files with a '.jpg' file extension and we can then use the Length property to return the number of files.



Get Sample Code
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim FileCount As Integer = FilesDirectoryCount("C:\Inetpub\wwwroot\website1\images", ".gif")
If FileCount = 0 Then
lblFilesInDirectory.Text = "There are no gif files in the directory."
ElseIf FileCount = 1 Then
lblFilesInDirectory.Text = "There is 1 gif files in the directory." Else
lblFilesInDirectory.Text = "There are " & FilesDirectoryCount("H:\Inetpub\wwwroot\website1\images", "*.gif") & " gif files in the directory."
End If
End Sub



Function FilesDirectoryCount(ByVal myDirectory As String, ByVal Extension As String) As Integer
Return Directory.GetFiles(myDirectory, "*" & Extension).Length
End Function

Posted by: Admin
Posted on: 10/20/2009 at 5:46 PM
Tags: , , ,
Categories: Asp.net
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (43) | Post RSSRSS comment feed

Unable to start debugging on the web server

Step 1. Open IIS Manager (Internbet Information Services)
Img: Control Panel

Img: IIS Wizard

Step 2. Right-click the website (in case you run it locally you only have Default web site) and pick Properties &
Img: Properties

Step 3. Choose "Directory Security" tab and click Edit on "Anonymous access and authentication control" 
Img: Directory Settings

Step 4. In the opening window, uncheck "Allow Anonymous access" and check "Integrated Windows Authentication" (allowing anonymous can make that you don't have enough permissions to debug) After that you also need to make sure your NT Debugger user is on Debugger users group (and in practise to attach to the aspnet_wp.exe process it also needs to be admin unless you change local security policies. Img: Authendication method

 


Posted by: Admin
Posted on: 10/8/2009 at 7:58 AM
Tags: , ,
Categories: Asp.net
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (38) | Post RSSRSS comment feed

Unable to start debugging on the web server. Debugging failed because integrated Windows authentication is not enabled

1. Open IIS Manager (Internbet Information Services) 2. Right-click the website (in case you run it locally you only have Default web site) and pick Properties 3. Choose "Directory Security" tab and click Edit on "Anonymous access and authentication control" 4. In the opening window, uncheck "Allow Anonymous access" and check "Integrated Windows Authentication" (allowing anonymous can make that you don't have enough permissions to debug) After that you also need to make sure your NT Debugger user is on Debugger users group (and in practise to attach to the aspnet_wp.exe process it also needs to be admin unless you change local security policies


Posted by: Admin
Posted on: 10/8/2009 at 7:58 AM
Tags: , ,
Categories: Asp.net
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (28) | Post RSSRSS comment feed

ASP.NET Hosting

System Requirements:

Processor:

  • Minimum: 733 MHz Pentium
  • Recommended: 1 Ghz or higher

Memory:

  • Minimum: 256 MB (Live websites) and 128 MB (development purposes)
  • Recommended: 512 MB or higher

Operating System:

  • Microsoft Windows 2000 Server
  • Microsoft Windows 2003 Server

Disk:

  • Minimum: 50 MB
  • Recommended: Depends on number and size stores and web pages.

Windows 2000/2003 Server Software Requirements:

  • Microsoft Internet Information Services (IIS) 5.0 or 6.0 or higher: This is the default web server pre-installed on Windows server platforms.
  • Current version has support for either:
    • .NET 1.1 Framework: Microsoft .NET Framework Version 1.1 (Download)
    • .NET 2.0 Framework: Microsoft .NET Framework Version 2.0 (Download)
  • MDAC 2.6 or greater: Microsoft Data Access Components (MDAC) 2.8 contains core Data Access components such as the Microsoft SQL Serverâ„¢ OLE DB provider and ODBC driver. (Download)

Database Requirements:

  • Microsoft SQL Server 2000, 2003: http://www.microsoft.com/sql/
  • Microsoft SQL Server 2000 Desktop Engine (MSDE 2000): (Free Version of SQL Server): http://www.microsoft.com/sql/msde/
  • Microsoft Access (97 or 2000 or higher): http://www.microsoft.com/office/access/default.asp (for development only)

Browser Requirements:

The browsers may be any one of the following:

  • Microsoft Internet Explorer
  • Firefox
  • Opera
  • Chrome

Posted by: Admin
Posted on: 9/25/2009 at 4:44 PM
Tags: ,
Categories: Asp.net
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (21) | Post RSSRSS comment feed

ToolBox HTML Control HTMLText

HTML Text Web Server Control

In ASP.NET environment,This article describes you how to work with HTML Text Control.In HTML environment, Text is an object that represents a Textbox in an HTML form. The Textbox control in a HTML form contains all instance of an <input type="text"> tag. Likewise, There are one more kind of textbox is <input type="password"> and <input type="reset">

There are several functions available to access the HTML Text.some of its funtions are as follows,

  • document.getElementById()
  • document.getElementByName()
Text Objects Properties
  • id -Sets or returns the id of a Text
  • form -Returns a reference to the form that contains the Text
  • accessKey -Sets or returns the keyboard key to access a Text
  • alt -Sets or returns an alternate text to display if a browser does not support Texts
  • disabled -Sets or returns whether or not a Text should be disabled
  • tabIndex -Sets or returns the tab order for a Text
  • name -Sets or returns the name of a Text
  • type -Returns the type of form element a Text is
  • maxLength - Sets or returns the maximum number of characters in a text field
  • readOnly -Sets or returns whether or not a text field should be read-only
  • value -Sets or returns the text that is displayed on the Text
  • title -Sets or returns an element's advisory title
  • lang -Sets or returns the language code for an element
  • dir -Sets or returns the direction of text
  • className -Sets or returns the class attribute of an element
Text Objects Methods
  • blur() -Performs focus when leave from the control
  • click() -Simulates a mouse-click on a Text
  • focus() -Performs focus when enter into the control

The following code snippets explains you the HTML Text in the web form.

in .aspx.cs page,

protected void AddButton_Click(Object sender, EventArgs e)
      {
         int Answer;
         Answer = Convert.ToInt32(txt1.Value) + Convert.ToInt32(txt2.Value);
         AnswerMessage.InnerHtml = Answer.ToString();
      }
        

in .aspx page,

 <form id="Form2" runat="server">
      <h3>Example </h3>
      <table>         
         <tr align="center">
            <td>
               <input ID="txt1"
                     Type="Text"
                      Size="2"
                      MaxLength="3"
                      Value="1"
                     runat="server"/>
            </td>
            <td>
               + 
            </td>
            <td>
               <input ID="txt2"
                     Type="Text"
                      Size="2"
                      MaxLength="3"
                      Value="1"
                      runat="server"/>
            </td>
            <td>
               =
            </td>
            <td>
              <span ID="AnswerMessage"
                     runat="server"/>
            </td>
         </tr>
         <tr>
            <td colspan="2">
               <asp:RequiredFieldValidator
                    ID="req1"
                    ControlToValidate="txt1"
                    ErrorMessage="Please enter a value.<br>"
                    Display="Dynamic"
                    runat="server"/>

               <asp:CompareValidator
                    ID="comp1"
                    ControlToValidate="txt1"
                    Operator="LessThan"
                    Type="Integer"
                    ValueToCompare="100"
                    ErrorMessage="Please enter an integer less than 100.<br>"
                    Display="Dynamic"
                    runat="server"/>
               <asp:CompareValidator
                    ID="comp2"
                    ControlToValidate="txt1"
                    Operator="GreaterThan"
                    Type="Integer"
                    ValueToCompare="0"
                    ErrorMessage="Please enter an integer greater than 0.<br>"
                    Display="Dynamic"
                   runat="server"/>
            </td>
            <td colspan="2">
               <asp:RequiredFieldValidator
                    ID="req2"
                    ControlToValidate="txt2"
                    ErrorMessage="Please enter a value.<br>"
                    Display="Dynamic"
                    runat="server"/>

               <asp:CompareValidator
                    ID="comp3"
                    ControlToValidate="txt2"
                    Operator="LessThan"
                    Type="Integer"
                    ValueToCompare="100"
                    ErrorMessage="Please enter an integer less than 100.<br>"
                    Display="Dynamic"
                    runat="server"/>

               <asp:CompareValidator
                    ID="comp4"
                    ControlToValidate="txt2"
                    Operator="GreaterThan"
                    Type="Integer"
                    ValueToCompare="0"
                    ErrorMessage="Please enter an integer greater than 0.<br>"
                    Display="Dynamic"
                    runat="server"/>
            </td>
            <td>
                 
            </td>
         </tr>
         <tr align="center">
            <td colspan="4">
               <input id="Submit1" Type="Submit"
                      Name="AddButton"
                      Value="Add"
                      OnServerClick="AddButton_Click"
                      runat="server"/>
                  
               <input id="Reset1" Type="Reset"
                      Name="AddButton"
                      Value="Reset"
                      runat="server"/>
            </td>
            <td>
                
            </td>
         </tr>
      </table>
   </form>
        
 
Related Links

Posted by: Admin
Posted on: 9/18/2009 at 4:55 PM
Tags: , ,
Categories: Asp.net
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (21) | Post RSSRSS comment feed