[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

creating folder in asp.net

Posted on 2009-12-27
3
Medium Priority
?
290 Views
Last Modified: 2013-11-26
hello,

my case is little bit different:

1st step:
i have a folder which has name Userfolder i have a problem that i want to create the sub folder according to user name inside the Userfolder.

2nd step:
when user login to my syste then if they have upload or download some thing they first find the userfolder and then create the file inside the folder if folder not found the create the folder first

3rd step:
how could i upload the text file using fileupload and place that file on particular user folder

4th step:
how could i show the download button when user want to download their folder only his/her folder content.

5th step:
i have a text written in the textbox and i want to first save in the text file and the userfolder and show the user to download for 3 formats only..

please i am very thankful if u help ..

Note:
1-no URL or referencing is allow (Strickly Prohabited)
2-code are in running state no copy the code, if u copy the other code then its must match my steps
3-i recommend that create your own according to my steps because its best..
4-i also get denied error when creating the folder in the subdirectory readly only error.
5-All code must be written on asp.net using C#.net

Thanks
0
Comment
Question by:AVARICESOFT
  • 2
3 Comments
 
LVL 3

Expert Comment

by:clintonlj
ID: 26127899
Well To start...
Make sure that the process that runs the script uses an account that has folder create and modify privledges...
1) Use the System.IO.Directory.CreateDirectory() function...
2) on the server side: use the <asp:FileUpLoad id="FileUpLoad1" runat="server" />
on the client side it will appear as the <input type="fileupload"> object...
3) on the server side: this object can be used to upload the data to the user's folder by calling the control's save command... (Store the contents in the user's folder)
4) when the user wants to download his directory contents simply enumerate the folder contents providing a link that points to each object.
5) note that the paths retrieved from file enumeration will give you a local path... You have to translate the local file system paths to a Uri or Relative folder internet URL path...
Example:

 c:\inetpub\wwwroot\site1\user1\mydoc1.xml
 c:\inetpub\wwwroot\site1\user1\coolpicture.jpg
 c:\inetpub\wwwroot\site1\user1\thumnail1.png
 c:\inetpub\wwwroot\site1\user1\recipe.txt

Translate these to:

http://www.myCoolSite/user1/mydoc1.xml
http://www.myCoolSite/user1/coolpicture.jpg
http://www.myCoolSite/user1/thumnail1.png
http://www.myCoolSite/user1/recipe.txt

NOTE: the user can then simply download the files via HTTP...
if you happen to put file files in an FTP accessible folder then you can use FTP links...
0
 
LVL 2

Expert Comment

by:shrinivasmw
ID: 26132043
----- ACCESS/PERMISSION ISSUE -----
About your

Note#4 : You will need ASPNET user on your machine need to have FULL CONTROL access to the folder/root folder of application, so that web application user can create/read/delete/edit the folder contents.

----- CREATE FOLDER -----
After having permissions/access to ASPNET user
You can create directory/folder at runtime using >>>> 
protected void btnSubmit_Click(object sender, EventArgs e)
{
try {
Directory.CreateDirectory(MapPath(".") + "\\" + txtDir.Text);
}
catch(Exception ex) {
     lblErrMessage.Text = ex.Message;
}
}

----- DOWNLOAD CODE -----
private void Download()
        {
           DwnFileName = "~\\Files\\Download\\" + templateFile;
            string fname = DwnFileName ;
            bool forceDownload = true ;

            string path = MapPath(fname);
            string name = Path.GetFileName(path);
            string ext = Path.GetExtension(path);
            string type = "";
            // set known types based on file extension  
            if (ext != null)
            {
                switch (ext.ToLower())
                {
                    case ".xls":
                    case ".xlsx":
                        type = "Application/msexcel";
                        break;

                    case ".doc":
                    case ".rtf":
                    case ".docx":
                        type = "Application/msword";
                        break;

                    case ".htm":
                    case ".html":
                        type = "text/HTML";
                        break;

                    case ".txt":
                        type = "text/plain";
                        break;


                }
            }
            if (forceDownload)
            {
                Response.AppendHeader("content-disposition", "attachment; filename=" + name);
            }
            if (type != "")
            {
                Response.ContentType = type;
            }
            Response.WriteFile(path);
            Response.End();
            lblupdownresult.Text = "";
        }
CHECK WHICH extension you want to support and keep only those extensions which you want to support.

It will solve your all issues.

SHRINIWAS WANI
0
 
LVL 2

Accepted Solution

by:
shrinivasmw earned 2000 total points
ID: 26132917
----- CREATE FOLDER -----
After having permissions/access to ASPNET user
You can create directory/folder at runtime using >>>> 
protected void btnSubmit_Click(object sender, EventArgs e)
{
try {
Directory.CreateDirectory(MapPath(".") + "\\" + txtDir.Text);
}
catch(Exception ex) {
     lblErrMessage.Text = ex.Message;
}
}

----- DOWNLOAD CODE -----
private void Download()
        {
           DwnFileName = "~\\Files\\Download\\" + templateFile;
            string fname = DwnFileName ;
            bool forceDownload = true ;

            string path = MapPath(fname);
            string name = Path.GetFileName(path);
            string ext = Path.GetExtension(path);
            string type = "";
            // set known types based on file extension  
            if (ext != null)
            {
                switch (ext.ToLower())
                {
                    case ".xls":
                    case ".xlsx":
                        type = "Application/msexcel";
                        break;

                    case ".doc":
                    case ".rtf":
                    case ".docx":
                        type = "Application/msword";
                        break;

                    case ".htm":
                    case ".html":
                        type = "text/HTML";
                        break;

                    case ".txt":
                        type = "text/plain";
                        break;


                }
            }
            if (forceDownload)
            {
                Response.AppendHeader("content-disposition", "attachment; filename=" + name);
            }
            if (type != "")
            {
                Response.ContentType = type;
            }
            Response.WriteFile(path);
            Response.End();
            lblupdownresult.Text = "";
        }

----- CREATE FOLDER ----- 
After having permissions/access to ASPNET user
You can create directory/folder at runtime using >>>>  
protected void btnSubmit_Click(object sender, EventArgs e)
{
try {
Directory.CreateDirectory(MapPath(".") + "\\" + txtDir.Text);
}
catch(Exception ex) {
     lblErrMessage.Text = ex.Message; 
}
}

----- DOWNLOAD CODE ----- 
private void Download()
        {
           DwnFileName = "~\\Files\\Download\\" + templateFile;
            string fname = DwnFileName ;
            bool forceDownload = true ;

            string path = MapPath(fname);
            string name = Path.GetFileName(path);
            string ext = Path.GetExtension(path);
            string type = "";
            // set known types based on file extension  
            if (ext != null)
            {
                switch (ext.ToLower())
                {
                    case ".xls":
                    case ".xlsx":
                        type = "Application/msexcel";
                        break;

                    case ".doc":
                    case ".rtf":
                    case ".docx":
                        type = "Application/msword";
                        break;

                    case ".htm":
                    case ".html":
                        type = "text/HTML";
                        break;

                    case ".txt":
                        type = "text/plain";
                        break;


                }
            }
            if (forceDownload)
            {
                Response.AppendHeader("content-disposition", "attachment; filename=" + name);
            }
            if (type != "")
            {
                Response.ContentType = type;
            }
            Response.WriteFile(path);
            Response.End();
            lblupdownresult.Text = "";
        }

Open in new window

0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses
Course of the Month17 days, 23 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question