You must Sign In to post a response.
  • Category: .NET

    Get files from adminstrative folder

    I want to get all files from the administrative privilege folder.
    Eg: i want to get the file name from MSOCache folder.
  • #764562
    If you run your application with 'Administrative rights' then it is possible other wise it is hard to get in to windows base drive (C:\) folder structure.
    second option is when you have deploy your exe on machine then you can right click on exe and set it as 'Run as Admin'.

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #764568
    Use Webclient i had written in one article regarding this.

  • #764579
    Hi Mahendiran,
    You can also apply read permissions to administrative privilege folder using c#.Net and read files from it as follows:
    DirectoryInfo objDirInfo = new DirectoryInfo(@"C:\Users\Administrator\Documents\Visual Studio 2012\Templates\ProjectTemplates");
    DirectorySecurity objDirSecurity = objDirInfo.GetAccessControl();
    string szLoggedInUserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
    //... if szLoggedInUserName does not contain domain name then you have to add it using
    string szCurrentUser = System.Environment.UserDomainName + "\\" + szLoggedInUserName;
    objDirSecurity.AddAccessRule(new FileSystemAccessRule(szCurrentUser, FileSystemRights.Read, AccessControlType.Allow));//... Read/Write and Allow/Deny
    //... Now GetFiles
    FileInfo[] objFiles = objDirInfo.GetFiles();

    Hope this will help you.
    Shashikant Gurav

  • #764590

    If you want to get files from admin folders then you must and should have administrative logins, in that case it is possible to achieve your goal.

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #764870
    Is this folder part of your application or is it outside of your application?

    Below is an example:

    string[] files = Directory.GetFiles(@"C:\MSOCache\");
    foreach (string f in files)

    Miss. Jain
    Microsoft Certified Technology Specialist in .Net

  • Sign In to post your comments