using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace Diagnostic_Tool_Blue_Screen
{
public static class CreateDirectories
{
static string outputfiles;
static string photofilesDir;
static string photofilesDir1;
static string photofilesDir2;
static string photofilesDir3;
static string temptxt;
static string tempphotos;
static string outputtext;
static string outputphotos;
public static void CreateDirectories()
{
outputfiles = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "OutputFiles");
if (!Directory.Exists(outputfiles))
{
Directory.CreateDirectory(outputfiles);
}
else
{
Directory.Delete(outputfiles, true);
Directory.CreateDirectory(outputfiles);
}
outputtext = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + outputfiles + "\\outputtext";
if (!Directory.Exists(outputtext))
{
Directory.CreateDirectory(outputtext);
}
else
{
Directory.Delete(outputtext, true);
Directory.CreateDirectory(outputtext);
}
outputphotos = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + outputfiles + "\\outputphotos";
if (!Directory.Exists(outputphotos))
{
Directory.CreateDirectory(outputphotos);
}
else
{
Directory.Delete(outputphotos, true);
Directory.CreateDirectory(outputphotos);
}
temptxt = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + outputfiles + "\\txtfiles";
if (!Directory.Exists(temptxt))
{
Directory.CreateDirectory(temptxt);
}
else
{
Directory.Delete(temptxt, true);
Directory.CreateDirectory(temptxt);
}
tempphotos = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\photosfiles";
if (!Directory.Exists(tempphotos))
{
Directory.CreateDirectory(tempphotos);
}
else
{
Directory.Delete(tempphotos, true);
Directory.CreateDirectory(tempphotos);
}
photofilesDir = outputphotos + "\\" + "photosfiles";
if (!Directory.Exists(photofilesDir))
{
Directory.CreateDirectory(photofilesDir);
}
else
{
Directory.Delete(photofilesDir, true);
Directory.CreateDirectory(photofilesDir);
}
photofilesDir1 = outputphotos + "\\" + "photosfiles1";
if (!Directory.Exists(photofilesDir1))
{
Directory.CreateDirectory(photofilesDir1);
}
else
{
Directory.Delete(photofilesDir1, true);
Directory.CreateDirectory(photofilesDir1);
}
photofilesDir2 = outputphotos + "\\" + "photosfiles2";
if (!Directory.Exists(photofilesDir2))
{
Directory.CreateDirectory(photofilesDir2);
}
else
{
Directory.Delete(photofilesDir2, true);
Directory.CreateDirectory(photofilesDir2);
}
photofilesDir3 = outputphotos + "\\" + "photosfiles3";
if (!Directory.Exists(photofilesDir3))
{
Directory.CreateDirectory(photofilesDir3);
}
else
{
Directory.Delete(photofilesDir3, true);
Directory.CreateDirectory(photofilesDir3);
}
}
}
}
Im running my program from visual studio 2012 pro as admin. I ran the visual studio as admin.
For example now the exception error is on the line:
Directory.CreateDirectory(outputtext);
UnauthorizedAccessException Access to the path 'C:\Users\bout0_000\AppData\Local\OutputFiles\outputtext' is denied.
And also windows it self throw me a window in the middle of screen say: Location is not available and then inside i see description to check network to check if disk i inserted....etc.
- If im running my program as admin why i dont have access ?
- Is there any directories maybe i can use that have access to any users when its under admin rights ? Or maybe without admin rights ? Instead this:
C:\Users\bout0_000\AppData\Local\OutputFiles\outputtext
Maybe there is some other location at C:\Users\bout0_000\AppData\Local that is not need admin at all ? Maybe C:\Users\bout0_000\AppData\Local\Temp ?
This is the complete exception error:
System.UnauthorizedAccessException was unhandled
HResult=-2147024891
Message=Access to the path 'C:\Users\bout0_000\AppData\Local\OutputFiles\outputtext' is denied.
Source=mscorlib
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj, Boolean checkHost)
at System.IO.Directory.InternalCreateDirectoryHelper(String path, Boolean checkHost)
at Diagnostic_Tool_Blue_Screen.CreateDirectories.CreateDirectoriesAtConstructor() in d:\C-Sharp\Diagnostic Tool Blue Screen\Diagnostic Tool Blue Screen\Diagnostic Tool Blue Screen\CreateDirectories.cs:line 40
at Diagnostic_Tool_Blue_Screen.Form1..ctor() in d:\C-Sharp\Diagnostic Tool Blue Screen\Diagnostic Tool Blue Screen\Diagnostic Tool Blue Screen\Form1.cs:line 127
at Diagnostic_Tool_Blue_Screen.Program.Main() in d:\C-Sharp\Diagnostic Tool Blue Screen\Diagnostic Tool Blue Screen\Diagnostic Tool Blue Screen\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: