Click here to Skip to main content
15,888,162 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more: , +
I have a login form, when user logins i want folder named Images to be displayed at run time.
When user clicks folder it opens another page (datas from sql).
I have created folder by using this code :

C#
string NewDirectory = Server.MapPath("Images");

       CreateDirectoryIfNotExists(NewDirectory);


Folder is also created. How to display the folder in my webpage?
Posted
Updated 19-Jan-14 1:31am
v2
Comments
Sampath Lokuge 19-Jan-14 7:32am    
Can you tell us your business scenario ?
sukumari1 19-Jan-14 11:41am    
creating a web page for photo studio. Separate login will be given for customers to view their albums (wedding, birthday...). each customer will have a separate username and pwd. When they login i want to display the Images folders. On clicking the folder they can view the images. No of folders vary from one customer to another which i have saved in database.
Kornfeld Eliyahu Peter 19-Jan-14 9:51am    
"Folder is also created" - so you have no problem with creating the folder, but want to show that new folder on your web-page!?
For what purpose?

 
Share this answer
 
You can list out all the directories on you page:

here is the code,

XML
<%@ Import Namespace="System.IO" %>
<html>
<body>
    <% foreach (var dir in new DirectoryInfo("E:\\MyFolder").GetDirectories()) { %>
        Directory: <%= dir.Name %><br />

        <% foreach (var file in dir.GetFiles()) { %>
            <%= file.Name %><br />
        <% } %>
        <br />
    <% } %>
</body>
</html>

OR :
C#
void GetDirectories(string path)
    {
        //use try catch since some directories may not allow you to read the subfolders eg:your antivruses Quarantine folder
        try 
        {
            string[] directoryList = System.IO.Directory.GetDirectories(path);
            if (directoryList.Length > 0)
            {
                sb.Append("<ul>");
                foreach (string directory in directoryList)
                {
                    System.IO.FileAttributes f = (new System.IO.DirectoryInfo(directory)).Attributes;
                    if ((f & System.IO.FileAttributes.Hidden) != System.IO.FileAttributes.Hidden)
                    {
                        sb.Append("<li>").Append(directory);
                        GetDirectories(directory);
                        sb.Append("</li>");
                    }
                }
                sb.Append("</ul>");
            }
        }
        catch
        {

        }
    }


src : here[^]
 
Share this answer
 
v3
Dear, Just Put this code in page load event.
This will create a folder named MyFolder.

C#
string strpath = @"C:/" + "MyFolder";
            //Condition to check if any directory exists with same name
            if (!(Directory.Exists(strpath)))
            {
                Directory.CreateDirectory(strpath);
               lblMessage. Text = "Directory Created";
            }
            else
            {
              lblMessage . Text = "Already Directory Exists with the same name";
            }
 
Share this answer
 
v2
C#
using System.IO;

string NewDirectory =Server.MapPath( "txtuser.text" );// login time text box value
 
Share this answer
 
v3
C#
if(Directory.Exists(Server.MapPath(Textbox1.Text)))
{
    Responses.write("folder Exists");
}
else
{
    (Directory.createdirectory(Server.MapPath(Textbox1.Text))) ;
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900