CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2002
    Location
    ireland
    Posts
    291

    DirectoryEntry for a single file

    How can one set security on single file?

    I'm trying to set the security permissions on an individual file on IIS. I've already used DirectoryEntry and it's Properties collection to set permissions at directory level but can't get it for file only, first of all I cannot new a DirectoryEntry with the url of a file, secondly if I new up a DirectoryEntry with the directory and then look for the Children it also fails, the debugger shows me an exception is thrown when trying to access the Children collection,

    Code:
    string myfileurl = url + "/myfile.asmx";
    
    //if (DirectoryEntry.Exists(myfileurl))//fails
    if (DirectoryEntry.Exists(url))
                {
    
                    DirectoryEntry entry = new DirectoryEntry(url);
                    DirectoryEntry myfilesEntry = entry.Children.Find("myfile.asmx", "");//fails, Children throws an exception
                    PropertyCollection props = myfilesEntry.Properties;
                    Int32 currentValue = (Int32)props["AuthFlags"].Value;
                    entry.Properties["AuthFlags"][0] = 4;
                    entry.CommitChanges();
    }

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: DirectoryEntry for a single file

    What is the exception?

  3. #3
    Join Date
    Aug 2002
    Location
    ireland
    Posts
    291

    Re: DirectoryEntry for a single file

    the Find throws a DirectoryNotFoundException, when I look at the Children in the debugger the Count property has thrown a NotImpementedException with the message "The method or operation is not implemented.".

    Could this mean that DirectoryEntry.Children.Find will only find child directories and not files?

    The answer appears to be Yes.
    A simple foreach shows the children as the directories only:
    foreach(DirectoryEntry childEntry in entry.Children)
    {
    Console.WriteLine(" child: " + childEntry.Name);
    }

    results:
    App_Code
    bin
    Last edited by ireland; November 12th, 2008 at 05:19 AM. Reason: addition

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: DirectoryEntry for a single file

    Take a look at the DirectoryInfo and FileInfo classes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured