none
Why does Environment.GetFolderPath return empty string? RRS feed

  • Question

  • var personalFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal)

    is returning an empty string for some of our users. 

    We tried this 

    var personalFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal, Environment.SpecialFolderOption.Create);

    However that still doesn't work - the folder does not get created.

    I tried PInvoking SHGetFolderPath

                int hr = SHGetFolderPath(IntPtr.Zero, 5, IntPtr.Zero, 0, lpszPath);

    it too (no surprise here) returns an empty string and a HResult of 80070035 

    I've asked users if they have roaming profiles or network drives - none of them do. The ones who reply confirm that c:\users\{name} doesn't exist. So I guess it makes sense that there is an empty string.

    I'm confused why this folder doesn't exist on these systems - how is windows even running :-)


    Minecraft WITH GUNS?? Coming soon(ish) [url=http://exatogames.com/guncraft/]GunCraft[/url]

    Tuesday, October 9, 2012 4:53 PM

Answers

  • Another release - another set of crashes :-) The new PInvoke also returns empty string - at least everything is consistent.

    To sumamrize

    • Environment.GetFolderPath(Environment.SpecialFolder.Personal, Environment.SpecialFolderOption.Create)
    • SHGetFolderPath(IntPtr.Zero, 5, IntPtr.Zero, 0, lpszPath)
    • SHGetKnownFolderPath(KnownFolder.Documents, 0, IntPtr.Zero, out pPath) [Vista Only]

    All return empty string. 

    Sadly no users share an email with me so I don't have any other way to work out what is unusual about these machines.

    Doesn't look like anyone here has much idea either though. I'll have to come up with some way to prompt the user in this edge case as its better than crashing.


    Minecraft WITH GUNS?? Play the beta for free right now! Guncraft

    Monday, November 19, 2012 6:09 PM

All replies

  • Are those users on OSes older than Vista by chance?

    -cd Mark the best replies as answers!

    Tuesday, October 9, 2012 6:38 PM
    Moderator
  • Error 80070035 is 'Network Path no found'.

    Are you running this code from ASP.NET ? If yes, then in client machine it runs under ASPNET account. So, obviosly Personal folder will be empty.

    The other possibility is that your program might be running on 'System' account. Especialy this happens with windows services. So, if your application is a windows service, then you need to use other methods.


    Please mark this post as answer if it solved your problem. Happy Programming!

    Wednesday, October 10, 2012 5:15 AM
  • Our error reports indicate this happens on Vista and Windows 7

    Microsoft Windows NT 6.1.7601 Service Pack 1
    Microsoft Windows NT 6.1.7600.0
    Microsoft Windows NT 5.1.2600 Service Pack 3

    So its not OS specific.


    Minecraft WITH GUNS?? Play the beta for free right now! Guncraft

    Tuesday, October 16, 2012 10:55 PM
  • No this is a client app running under the current users account. 

    How did you find that error code? I tried the error lookup tool and it has nothing.

    If thats a network path then this could be a roaming profile type thing maybe? I know a couple of the users had .edu accounts so maybe their personal folder is on a LAN drive. In that case I would expect to get back a network drive rather than am empty string. At least that seems to be sensible...

    Since SHGetFolderPath is deprecated preVista I'm going to add some debug code to call SHGetKnownFolderPath and see if that gives a better or different error message. .Net calls the deprecated version so its no wonder they agree with each other.



    Minecraft WITH GUNS?? Play the beta for free right now! Guncraft

    Tuesday, October 16, 2012 11:08 PM
  • Another release - another set of crashes :-) The new PInvoke also returns empty string - at least everything is consistent.

    To sumamrize

    • Environment.GetFolderPath(Environment.SpecialFolder.Personal, Environment.SpecialFolderOption.Create)
    • SHGetFolderPath(IntPtr.Zero, 5, IntPtr.Zero, 0, lpszPath)
    • SHGetKnownFolderPath(KnownFolder.Documents, 0, IntPtr.Zero, out pPath) [Vista Only]

    All return empty string. 

    Sadly no users share an email with me so I don't have any other way to work out what is unusual about these machines.

    Doesn't look like anyone here has much idea either though. I'll have to come up with some way to prompt the user in this edge case as its better than crashing.


    Minecraft WITH GUNS?? Play the beta for free right now! Guncraft

    Monday, November 19, 2012 6:09 PM