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'.

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

  • #764568
    Use Webclient i had written in one article regarding this. http://www.dotnetspider.com/resources/46126-Download-a-file-of-a-given-URL-Using-WebClient-class-in-c.aspx
    SRI RAMA PHANI BHUSHAN KAMBHAMPATI

  • #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
    objDirInfo.SetAccessControl(objDirSecurity);
    //... Now GetFiles
    FileInfo[] objFiles = objDirInfo.GetFiles();

    Hope this will help you.
    Regards,
    Shashikant Gurav
    shashikantgurav22@gmail.com

  • #764590
    Hi,

    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.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #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)
    {
    Response.Write(f);
    }

    Miss. Jain
    Microsoft Certified Technology Specialist in .Net


Sign In to post your comments