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 (1) | 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 (1) | 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 (1) | Post RSSRSS comment feed