BeanSoftware Logo
 

 
ASP.NET Database Search Control
 
 

 
 Home
    Shop
    Advertise
    Write For Us
    Affiliate
    Newsletter
    Contact

How To Make Directory In ASP.NET?

To create directory on web server with ASP.NET server side code, you can use this code:

[ C# ]

using System;
using System.Data;
using System.Configuration;
// We need this namespace to create directory
using System.IO;
 
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string NewDir = Server.MapPath("New Folder");
        // Call function for creating a directory
        MakeDirectoryIfExists(NewDir);
    }
 
    private void MakeDirectoryIfExists(string NewDirectory)
    {
        try
        {
            // Check if directory exists
            if (!Directory.Exists(NewDirectory))
            {
                // Create the directory.
                Directory.CreateDirectory(NewDirectory);
            }
        }
        catch (IOException _ex)
        {
            Response.Write(_ex.Message);
        }
    }
}

[ VB.NET ]

' We need this namespace to make a directory
Imports System.IO
 
Partial Class _Default
    Inherits System.Web.UI.Page
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim NewDir As String = Server.MapPath("New Folder")
        ' Call function for creating a directory
        MakeDirectoryIfExists(NewDir)
    End Sub
 
    Private Sub MakeDirectoryIfExists(ByVal NewDirectory As String)
        Try
            ' Check if directory exists
            If Not Directory.Exists(NewDirectory) Then
                ' Create the directory.
                Directory.CreateDirectory(NewDirectory)
            End If
        Catch _ex As IOException
            Response.Write(_ex.Message)
        End Try
    End Sub



Related articles:

1. Implementing Web Service Clients
2. Managing State in Web Services

FAQ toolbar: Submit FAQ  |  Tell A Friend  |  Add to favorites  |  Feedback



Copyright © 2002-2008 Bean Software. All rights reserved.