0

so i have this code:

        try
    {
        if ((uplImage.FileName != ""))
        {
            //to allow only jpg gif and png files to be uploaded.
            string extension = Path.GetExtension(uplImage.PostedFile.FileName);
            if (((extension == ".jpg") || ((extension == ".gif") || (extension == ".png"))))
            {
                DALBio bio = new DALBio();
                byte[] raw;
                FileStream fs = new FileStream(uplImage.PostedFile.FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                raw = new byte[fs.Length];
                fs.Read(raw, 0, Convert.ToInt32(fs.Length));

                bio.PlayerID = Session["playerID"].ToString();
                bio.Pending = 'Y';
                bio.Photo = raw;
                DALBio.insertImage(bio);
            }
        }
    }
    catch (Exception e1)
    {
        Label1.Text = e1.InnerException.ToString();
    }

and the program breaks on the FileStream fs = new FileStream line. at first my image was in my downloads folder and it said access to c:\prog(x86)\filefolder\file\folder\and so on was denied

so i moved it to my images folder, and i got the same error to a different folder on c. my google searches have said it oculd be a permissions thing (if its UAC, that makes no sense, i have all permissions possible across the board). another thing is it could be a change in my web.config file about application settings, however without any examples or better insight than what i did get from those searches, i am lost.

dwarf
  • 445
  • 2
  • 9
  • 23
  • 1
    The account used by .NET is not your account. Even though you have permissions on your account it does not matter. You have to give IIS the permissions to the folder. – AliK May 15 '13 at 01:05

1 Answers1

0

You have to give account under which ASP.NET worker process runs "write" permissions. Ordinary it's Network Services account.

Yuriy Galanter
  • 38,833
  • 15
  • 69
  • 136