Results 1 to 13 of 13

Thread: DirectoryInfo.GetDirectories() not working properly in .net 1.1

  1. #1
    Lively Member
    Join Date
    Apr 06
    Location
    CA, USA
    Posts
    81

    DirectoryInfo.GetDirectories() not working properly in .net 1.1

    (language C#)
    When I use this code:

    DirectoryInfo drInfo = new DirectoryInfo(System.Environment.GetFolderPath(Environment.SpecialFolder.Favorites));

    DirectoryInfo[] subDrInfo = drInfo.GetDirectories();
    if (subDrInfo.Length > 0)


    subDirInfo.Length returns 1 which is not true

    When I use

    DirectoryInfo drInfo = new DirectoryInfo(@"C:\Documents and Settings\myUserName\Favorites");
    DirectoryInfo[] subDrInfo = drInfo.GetDirectories();
    if (subDrInfo.Length > 0)

    subDirInfo.Length returns 3 which is correct

    But I have to use Environment.SpecialFolder.Favorites instead of giving full path of the folder. The same code works fine in .net 2.0 . Any help please?

  2. #2
    ASP.NET Moderator mendhak's Avatar
    Join Date
    Feb 02
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174

    Re: DirectoryInfo.GetDirectories() not working properly in .net 1.1

    When debugging, is

    System.Environment.GetFolderPath(Environment.SpecialFolder.Favorites)

    the same as

    C:\Documents and Settings\myUserName\Favorites

    ?

  3. #3
    Lively Member
    Join Date
    Apr 06
    Location
    CA, USA
    Posts
    81

    Re: DirectoryInfo.GetDirectories() not working properly in .net 1.1

    I thought it is the same. but for my surprise when I debug the path is like:

    C:\Documents and Settings\myComputerName\ASPNET\Favorites (when I run from VS 2003)

    when I run the application from VS 2005 then it is going to:

    C:\Documents and Settings\myUserName\Favorites

    Thanks for the question Mendhak...

    How can I get User's Favorites?

  4. #4
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 03
    Location
    USA, Maryland
    Posts
    4,981

    Re: DirectoryInfo.GetDirectories() not working properly in .net 1.1

    Well this is a Web Application. It doesn't seem to make sense why you'd want to set the favorites on the server machine unless everything is setup through AD and the web application impersonates each user that logs in (so it would be able to modify their favorites on roaming profiles).

    Why do you need to modify the server's favorites? Remember, you can't get the user's favorites (that would be a large security and privacy risk) unless you're in a setup where everything in hooked into AD, the site impersonates each user and the computer profiles are setup so favorites travel with the logins.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  5. #5
    Lively Member
    Join Date
    Apr 06
    Location
    CA, USA
    Posts
    81

    Re: DirectoryInfo.GetDirectories() not working properly in .net 1.1

    Actually I wanted to read Favorites links from the logged in user's browser and add them to a sharepoint portal list. So I am lloking for Client machines' Favorites but not of the server.

  6. #6
    ASP.NET Moderator mendhak's Avatar
    Join Date
    Feb 02
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174

    Re: DirectoryInfo.GetDirectories() not working properly in .net 1.1

    You can't read the user's favorites using server side code. It was curious to see you reading the Favorites folder on the server.

    I won't make the ActiveX/Java applet suggestion to you either about this as it counts as invasion of privacy. I don't want any application or any person knowing about my bookmarked belly-button lint websites.

  7. #7
    ASP.NET Moderator mendhak's Avatar
    Join Date
    Feb 02
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174

    Re: DirectoryInfo.GetDirectories() not working properly in .net 1.1

    You can't read the user's favorites using server side code. It was curious to see you reading the Favorites folder on the server.

    I won't make the ActiveX/Java applet suggestion to you either about this as it counts as invasion of privacy. I don't want any application or any person knowing about my bookmarked belly-button lint websites.

  8. #8
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 03
    Location
    USA, Maryland
    Posts
    4,981

    Re: DirectoryInfo.GetDirectories() not working properly in .net 1.1

    Of course if it's an intranet with AD authentication you can use impersonation and roaming profiles to possinly get the user's favorites but that's a pain in the ass. Why do they have to be in SharePoint? Why can't the users have their own favorites and collaborate on others?

    A better solution may be utilizing Firefox and their custom software that allows you to store favorites remotely. You may be able to use that to collaborate.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  9. #9
    Lively Member
    Join Date
    Apr 06
    Location
    CA, USA
    Posts
    81

    Re: DirectoryInfo.GetDirectories() not working properly in .net 1.1

    The actual requirement is:

    there is a webpart in the portal home page "My Links" which shows the user's favorites links in his/her browser and allows the user to click on the link to get that page. It's an intranet portal.

    Is there any clientside code for this or any other way?

  10. #10
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 03
    Location
    USA, Maryland
    Posts
    4,981

    Re: DirectoryInfo.GetDirectories() not working properly in .net 1.1

    Quote Originally Posted by kiran_q8
    The actual requirement is:

    there is a webpart in the portal home page "My Links" which shows the user's favorites links in his/her browser and allows the user to click on the link to get that page. It's an intranet portal.

    Is there any clientside code for this or any other way?
    There are only two ways of doing this that I can think of:

    1. Like I've mentioned a few times before, if AD supports this (and I don't know that it does) and your intranet is authenticating through AD then you may be able to use impersonation, have the website impersonate as the user who's browsing the page, and grab their bookmarks from their roaming profile. Kind of odd but if favorites are setup via AD to travel with the user and you're using AD authentication then I don't see why it wouldn't be possible.

    2. Write an ugly ActiveX object, install it onto each user's machine and somehow sync between Sharepoint and the user's account. Pretty ugly but it can work (it'll only work with IE though).

    There is simply no way of doing this with client side code otherwise every website you visit would have all of your favorites which would be a huge security issue as well as a privacy issue.

    Honestly, this is a very odd requirement so you may want to verify that your client understands the disconnect between client and server and the security / privacy protections that are in place. Either solution you make may not be compatible with any browser but IE.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  11. #11
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 01
    Location
    NJ - USA (Near NYC)
    Posts
    23,021

    Re: DirectoryInfo.GetDirectories() not working properly in .net 1.1

    Its not totally odd.. Many online link services (like favorites.live.com, or the google based one) will read the local links from your browser in order to migrate them to the online service. So I have seen totally valid uses for something like this.

    It was nice to see when I moved to an online service based link repository, I didn't have to re-enter the many favorites I had cached locally.

    And at the risk of actually pimping an MS live service, their favorites service is way better than googles, and I really enjoy using it.
    Using VB.NET 2010/.NET 2.0 through 4.0 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  12. #12
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 05
    Location
    Los Angeles, Univ. of Southern California
    Posts
    2,938

    Re: DirectoryInfo.GetDirectories() not working properly in .net 1.1

    In this case, you don't want to read files, instead you need Properties of those files. If you open Favorites folder in your system, which is:

    C:/Documents and Settings/username/Favorites

    you will find Internet Shortcuts, and not valid Text files or HTML files.

    You can create object of FileSystemObject as an ActiveXObject in JavaScript and can read files.

    You ought to know 2 things:
    • This can be an invasion of privacy.
    • This will work only in Internet Explorer.


    MSDN - FileSystemObject Basics
    Show Appreciation. Rate Posts.

  13. #13
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 03
    Location
    USA, Maryland
    Posts
    4,981

    Re: DirectoryInfo.GetDirectories() not working properly in .net 1.1

    Quote Originally Posted by kleinma
    Its not totally odd.. Many online link services (like favorites.live.com, or the google based one) will read the local links from your browser in order to migrate them to the online service. So I have seen totally valid uses for something like this.
    Typically those are plug-ins where as this is a run-at-the-site kind of thing. I would say write a plug-in to do exactly what you want rather than rigging a site to do it when you visit it (like the current suggestions / methods).
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer 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
  •