Link to home
Start Free TrialLog in
Avatar of AVARICESOFT
AVARICESOFTFlag for Pakistan

asked on

creating folder in asp.net

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
Avatar of clintonlj
clintonlj

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...
----- 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
ASKER CERTIFIED SOLUTION
Avatar of shrinivasmw
shrinivasmw
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial