System.Environment.GetFolderPath does not appear to be available in Window Store envrionment__

Answered System.Environment.GetFolderPath does not appear to be available in Window Store envrionment__

  • Monday, September 24, 2012 11:05 PM
     
     

    I'm in the process of developing a prototype Microsoft Store (formerly "Metro") application and am having trouble getting the following statement to compile on Microsoft Visual Studio Ultimate RC:

            using System;

            ...

            StringsSpecialFolderPath = System.Environment.GetFolderPath(Environment.SpecialFolder.MyVideos);

    I'm getting the error:

            'System.Environment' does not contain a reference to 'GetForlderPath'

    This statement works with code that was initially developed using an earlier version of VS 2012, but I can't get it to compile in the code for the new application that I'm writing.

    Any suggestions on how to fix this problem would be greatly appreciated.

    Best Regards,

    Darwin

All Replies

  • Monday, September 24, 2012 11:17 PM
     
      Has Code

    you can use: http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.knownfolders.videoslibrary.aspx

    KnownFolders.VideoLibrary


    and dont forget to change the manifest file
  • Tuesday, September 25, 2012 4:24 PM
     
     

    Thanks for the suggestion Dave.  This is closer, but now exactly what I'm looking for.  By including the line:

            String strSpecialFolderPath = KnownFolders.VideoLibrary.Name;

    in my code, 'strSpecialFolderPath' is only get the actual "Videos" folder.  I'm looking for the fully qualified pathname to the "Videos" folder (e.g., "C:\users\<user_name>\Videos").  Make sense?  Also, using "KnownFolders.VideoLibrary.Name" doesn't work either, as this just returns the empty string ("").

    Note that the code that I included in my original posting actually works for one of my Windows Store applications.  Very strange ...

    Thanks in advance everyone.

    Darwin

  • Tuesday, September 25, 2012 4:39 PM
    Moderator
     
     

    Why are you looking for the path? What is the scenario here? There probably is a better way to achieve that higher goal.

    The Videos library is not a file system directory and doesn't have a path. It is a compilation of items from multiple locations. Typically c:\users\<user name>\Videos is one of those locations along with c:\users\Public\Videos, but the user may set more (or fewer) included locations. Individual items in the Videos library may have a path if they are from the file system, but they may not if they aren't.

    See Windows Libraries for more information about libraries.

    --Rob

  • Tuesday, September 25, 2012 6:20 PM
     
     

    Rob,

    I'll try to briefly explain what I'm doing, but first want to clarify something.  It's actually the "My Videos" folder that I need the fully qualified pathname for, and *not* the Public "Videos" folder.

    That being said, we are storing videos (".mp4" files, etc.) and an ".xml" file in the "My Videos" folder.  The '.xml" file is used to store the fully qualified pathname to each video files so that the video can be played with our video/media player on the desktop.  (A file association containing this pathname is then used to switch from the Windows Store application to the standard desktop where the player resides.)  The desktop application needs to know this fully qualified pathname in order to play the video.

    I hope this helps to better clarify what we're trying to achieve.

    Thanks again for your assistance everyone.

    Darwin

  • Thursday, September 27, 2012 4:22 PM
     
     

    Any other suggestions out there folks?  I still haven't solved my problem.  Perhaps I'm missing something in the previous responses. :-) 

    I simply need to be the fully qualified pathname of the currently logged in users "My Videos" folder.

    Thanks in advance everyone.

    Darwin

  • Thursday, September 27, 2012 7:56 PM
    Moderator
     
     Answered

    You will need to change your design. Windows Store apps can access the library itself, but don't get direct access to its contents. There is no guarantee that a file saved to the Video Library will be stored in the c:\users\<user>\videos. While that's a default, the user may have set up the system differently.

    The scenario you are aiming for to interop between a Windows Store app and a desktop app is not supported and cannot be cleanly achieved.

    --Rob

  • Thursday, September 27, 2012 8:59 PM
     
     
    or let the user select a folder the first time when using the application where he wants to drop the videos.. that can be an alternative maybe
  • Thursday, September 27, 2012 9:41 PM
     
     

    Rob States:

    > You will need to change your design. Windows Store apps can access the library itself, but don't get direct access to its contents. There is no guarantee that a file saved to the Video Library will be stored in the c:\users\<user>\videos. While that's a default, the user may have set up the system differently.

    So I forgot to provide yet another vital piece of data on my problem.  My Windows Store doesn't need to read or write the file in the "My Videos" folder.  I only need to get the full qualified path to the file so that I can update (write to) an XML file that contains this fully qualified path.  Hopefully this clarifies what I'm looking for.

    I only want to be able to compile and run the following statement or it's equivalent:

            System.Environment.GetFolderPath(Environment.SpecialFolder.MyVideos);

    This doesn't seem to compile for my current Windows Store C# application.

    > The scenario you are aiming for to interop between a Windows Store app and a desktop app is not supported and cannot be cleanly achieved.

    Yes, I'm very well aware of this.  Thanks for this update though.

    --Rob

  • Friday, September 28, 2012 12:21 AM
    Moderator
     
     Answered

    I only want to be able to compile and run the following statement or it's equivalent:

            System.Environment.GetFolderPath(Environment.SpecialFolder.MyVideos);

    This doesn't seem to compile for my current Windows Store C# application.

    Windows Store apps do not have an equivalent to this. They can get the library folder itself, but cannot directly get the component directories. If you are looking at a file in the library then you can get the path with StorageFile.Path, with the caveat that not all StorageFiles have paths.

    --Rob

  • Friday, September 28, 2012 8:00 PM
     
     Answered

    Yes, we finally have success.  Using your StorageFolder.Path suggestion I got a empty folder "Path" returned.  However, after first opening (or creating if it didn't already exist) another folder under "My Videos" which I needed anyway, I was then able to use the "Path" method on the "StorageFolder" created (or opened) to get the fully qualified path I have been looking for.

    My code works like a champ now.  Thanks again for you prompt and professional assistance with my problem.

    Best Regards,

    Darwin

  • Wednesday, January 16, 2013 10:11 AM
     
     Proposed

    Hi 

               I am also facing same kind of problem Help me to solve this?

    string basePath = ( Application.isEditor ) ? Application.dataPath : Environment.GetFolderPath( Environment.SpecialFolder.Personal );

    Help to solve this?

    • Proposed As Answer by SARWON Wednesday, January 16, 2013 10:16 AM
    •  
  • Wednesday, January 16, 2013 10:12 AM
     
     Proposed

    Hi 

               I am also facing same kind of problem Help me to solve this?

    string basePath = ( Application.isEditor ) ? Application.dataPath : Environment.GetFolderPath( Environment.SpecialFolder.Personal );

    Help to solve this?

    • Proposed As Answer by SARWON Wednesday, January 16, 2013 10:16 AM
    •