0

Following is the code of store attachment of email temporary. This code is working fine with my application. When I crease EXE file. I get this error:

"Access to the path 'C:\Program Files (x86)\Application Name\Temp' is denied"

if (!Directory.Exists(String.Format("{0}\\Temp", Application.StartupPath)))
    Directory.CreateDirectory(String.Format("{0}\\Temp", Application.StartupPath));
FileInfo f = new FileInfo(String.Format(@"{0}\Temp\{1}", Application.StartupPath, Atchment.Filename));
if (!f.Exists)
{
    using (var fs = new FileStream(String.Format(@"{0}\Temp\{1}", Application.StartupPath, Atchment.Filename), FileMode.Create))
    {
        int fileLength = (int)Atchment.FileSize;
        byte[] rawdata = (byte[])Atchment.File;
        int byteCount = rawdata.Length;
        fs.Write(rawdata, 0, byteCount);
    }
}

I have tried with permission also by DirectorySecurity folderSecurity = Directory.GetAccessControl(path); but it didn't work. What am I doing wrong?

AlG
  • 14,697
  • 4
  • 41
  • 54
NJ Bhanushali
  • 901
  • 1
  • 12
  • 21

0 Answers0