ERROR: System.Environment.SpecialFolder' does not contain a definition for 'CommonApplicationData'

前端 未结 2 1454
醉梦人生
醉梦人生 2021-01-17 02:41

I have the code to save a file in a folder in directory

string timestamp = DateTime.Now.ToString(\"MM-dd-yyyy.HH-mm-ss\");
                var file = File.Cr         


        
相关标签:
2条回答
  • 2021-01-17 03:06

    As per the Exceptions section of documentation,the above exception is thrown when

    ArgumentException ------- folder is not a member of System.Environment.SpecialFolder.

    It means the OS where you are running this command does not have Environment.SpecialFolder.CommonApplicationData as one of the special folder.

    For knowledge,
    Environment.SpecialFolder.ApplicationData is the most common one. This folder holds per-user, non-temporary application-specific data, other than user documents. A common example would be a settings or configuration file.

    Environment.SpecialFolder.CommonApplicationData is similar, but shared across users. You could use this to store document templates, for instance.

    Environment.SpecialFolder.LocalApplicationData is a non-roaming alternative for ApplicationData. As such, you'd never store important data there. However, because it's non-roaming it is a good location for temporary files, caches, etcetera. It's typically on a local disk.

    I think the problem may be that Environment.SpecialFolder.CommonApplicationData is common and shared between different users and the user with which you have logged in is not having rights to access the folder or the Visual Studio has not been started in Admin mode.

    EDIT Look at link and try to add a manual registry Common AppData defined in the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\

    0 讨论(0)
  • 2021-01-17 03:20

    Given you are asking about a .NET Windows Phone application as per the tags

    I think your problem is that a .NET Windows Phone application does not have direct access to the file system; it can only access IsolatedStorage this is by design.

    I would quote a Microsoft source for this but I can't seem to find one!

    EDIT See this article from MSDN

    0 讨论(0)
提交回复
热议问题