Click here to Skip to main content
15,302,501 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i am trying to up load a file to a folder i.e path is "C:\inetpub\wwwroot\admin\books\" i am using the code like this
C#
protected void Button1_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
            try
            {
                FileUpload1.SaveAs(Server.MapPath("~/books/" + 
                     FileUpload1.FileName));
                Label1.Text = "File name: " +
                     FileUpload1.PostedFile.FileName + "<br>" +
                     FileUpload1.PostedFile.ContentLength + " kb<br>" +
                     "Content type: " +
                     FileUpload1.PostedFile.ContentType;
            }
            catch (Exception ex)
            {
                Label1.Text = "ERROR: " + ex.Message.ToString();
            }
        else
        {
            Label1.Text = "You have not specified a file.";
        }
    }</br></br>


i completed debug successfully. but when i try too upload a file it shows the error like this "Access to the path '~/books/' is denied." at that i am set the access permissions in iis there i am unable to set the correct permissions to the virtual directory of my web application. by Google search i found a solution like this "right click on virtual directory then go to properties there you can give the permissions" but i didn't get the properties dialogue on right click of my virtual directory. i am using win7 with iis6. please any one help how to set permissions and regarding upload any file to the virtual directory in localhost.
Posted
Comments
Uday P.Singh 3-Aug-11 7:07am
   
I don't think Win7 comes with IIS6, it should be IIS7

You need to set the access properties on the actual folder, not the virtual one in the IIS config app. Find the physical folder on the disk, do right click/Properties and the tab you want is Security. You'll want to give the ASPNET user read, write and modify access for an upload storage zone, I think.
   
Check this!
   
v2
Comments
BobJanova 3-Aug-11 7:26am
   
Not sure why this was downvoted, the 'Create the data directory' section explains how to set the permissions.

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