Application.UserAppDataPath Application.UserAppDataPath Application.UserAppDataPath Application.UserAppDataPath Property

정의

사용자의 애플리케이션 데이터 경로를 가져옵니다.Gets the path for the application data of a user.

public:
 static property System::String ^ UserAppDataPath { System::String ^ get(); };
public static string UserAppDataPath { get; }
member this.UserAppDataPath : string
Public Shared ReadOnly Property UserAppDataPath As String

속성 값

사용자의 애플리케이션 데이터 경로입니다.The path for the application data of a user.

예제

다음 코드 예제에서는 두 개의 폼을 표시 하 고 두 형태 모두 닫을 때 애플리케이션을 종료 합니다.The following code example displays two forms and exits the application when both forms are closed. 애플리케이션 시작 및 종료, 경우에 각 폼의 위치가 기억 됩니다.When the application starts and exits, the position of each form is remembered. 이 예제에서는 UserAppDataPath 속성을 사용자에 대 한 애플리케이션 데이터를 저장 합니다.This example demonstrates using the UserAppDataPath property to store application data for the user.

클래스 MyApplicationContext 에서 상속 ApplicationContext 각 폼 닫혀 있고 둘 경우 현재 스레드를 종료 하는 시기를 추적 하 고 있습니다.The class MyApplicationContext inherits from ApplicationContext and keeps track when each form is closed, and exits the current thread when they both are. 클래스는 사용자에 대 한 각 폼의 위치를 저장합니다.The class stores the positions of each form for the user. 폼 위치 데이터 라는 파일에 저장 됩니다 Appdata.txt 기준 위치에 만든 UserAppDataPath합니다.The form position data is stored in a file titled Appdata.txt that is created in the location determined by UserAppDataPath. 합니다 Main 메서드 호출 Application.Run(context) 지정 하는 애플리케이션을 시작 합니다 ApplicationContext합니다.The Main method calls Application.Run(context) to start the application given the ApplicationContext.

이 코드는 예제에 표시 된 발췌 된 ApplicationContext 클래스 개요입니다.This code is an excerpt from the example shown in the ApplicationContext class overview. 간 결함을 위해 일부 코드가 표시 되지 않습니다.Some code is not shown for the purpose of brevity. 참조 ApplicationContext 전체 코드 샘플에 대 한 합니다.See ApplicationContext for the whole code listing.

   MyApplicationContext()
   {
      _formCount = 0;
      
      // Handle the ApplicationExit event to know when the application is exiting.
      Application::ApplicationExit += gcnew EventHandler( this, &MyApplicationContext::OnApplicationExit );
      try
      {
         
         // Create a file that the application will store user specific data in.
         _userData = gcnew FileStream( String::Concat( Application::UserAppDataPath, "\\appdata.txt" ),FileMode::OpenOrCreate );
      }
      catch ( IOException^ e ) 
      {
         
         // Inform the user that an error occurred.
         MessageBox::Show( "An error occurred while attempting to show the application. The error is: {0}", dynamic_cast<String^>(e) );
         
         // Exit the current thread instead of showing the windows.
         ExitThread();
      }

      
      // Create both application forms and handle the Closed event
      // to know when both forms are closed.
      _form1 = gcnew AppForm1;
      _form1->Closed += gcnew EventHandler( this, &MyApplicationContext::OnFormClosed );
      _form1->Closing += gcnew CancelEventHandler( this, &MyApplicationContext::OnFormClosing );
      _formCount++;
      _form2 = gcnew AppForm2;
      _form2->Closed += gcnew EventHandler( this, &MyApplicationContext::OnFormClosed );
      _form2->Closing += gcnew CancelEventHandler( this, &MyApplicationContext::OnFormClosing );
      _formCount++;
      
      // Get the form positions based upon the user specific data.
      if ( ReadFormDataFromFile() )
      {
         
         // If the data was read from the file, set the form
         // positions manually.
         _form1->StartPosition = FormStartPosition::Manual;
         _form2->StartPosition = FormStartPosition::Manual;
         _form1->Bounds = _form1Position;
         _form2->Bounds = _form2Position;
      }

      
      // Show both forms.
      _form1->Show();
      _form2->Show();
   }

   void OnApplicationExit( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      
      // When the application is exiting, write the application data to the
      // user file and close it.
      WriteFormDataToFile();
      try
      {
         
         // Ignore any errors that might occur while closing the file handle.
         _userData->Close();
      }
      catch ( Exception^ ) 
      {
      }

   }

private:

private MyApplicationContext()
{
    _formCount = 0;

    // Handle the ApplicationExit event to know when the application is exiting.
    Application.ApplicationExit += new EventHandler(this.OnApplicationExit);

    try
    {
        // Create a file that the application will store user specific data in.
        _userData = new FileStream(Application.UserAppDataPath + "\\appdata.txt", FileMode.OpenOrCreate);

    }
    catch (IOException e)
    {
        // Inform the user that an error occurred.
        MessageBox.Show("An error occurred while attempting to show the application." +
                        "The error is:" + e.ToString());

        // Exit the current thread instead of showing the windows.
        ExitThread();
    }

    // Create both application forms and handle the Closed event
    // to know when both forms are closed.
    _form1 = new AppForm1();
    _form1.Closed += new EventHandler(OnFormClosed);
    _form1.Closing += new CancelEventHandler(OnFormClosing);
    _formCount++;

    _form2 = new AppForm2();
    _form2.Closed += new EventHandler(OnFormClosed);
    _form2.Closing += new CancelEventHandler(OnFormClosing);
    _formCount++;

    // Get the form positions based upon the user specific data.
    if (ReadFormDataFromFile())
    {
        // If the data was read from the file, set the form
        // positions manually.
        _form1.StartPosition = FormStartPosition.Manual;
        _form2.StartPosition = FormStartPosition.Manual;

        _form1.Bounds = _form1Position;
        _form2.Bounds = _form2Position;
    }

    // Show both forms.
    _form1.Show();
    _form2.Show();
}

private void OnApplicationExit(object sender, EventArgs e)
{
    // When the application is exiting, write the application data to the
    // user file and close it.
    WriteFormDataToFile();

    try
    {
        // Ignore any errors that might occur while closing the file handle.
        _userData.Close();
    }
    catch { }
}
Public Sub New()
    MyBase.New()
    _formCount = 0

    ' Handle the ApplicationExit event to know when the application is exiting.
    AddHandler Application.ApplicationExit, AddressOf OnApplicationExit

    Try
        ' Create a file that the application will store user specific data in.
        _userData = New FileStream(Application.UserAppDataPath + "\appdata.txt", FileMode.OpenOrCreate)

    Catch e As IOException
        ' Inform the user that an error occurred.
        MessageBox.Show("An error occurred while attempting to show the application." +
                        "The error is:" + e.ToString())

        ' Exit the current thread instead of showing the windows.
        ExitThread()
    End Try

    ' Create both application forms and handle the Closed event
    ' to know when both forms are closed.
    _form1 = New AppForm1()
    AddHandler _form1.Closed, AddressOf OnFormClosed
    AddHandler _form1.Closing, AddressOf OnFormClosing
    _formCount = _formCount + 1

    _form2 = New AppForm2()
    AddHandler _form2.Closed, AddressOf OnFormClosed
    AddHandler _form2.Closing, AddressOf OnFormClosing
    _formCount = _formCount + 1

    ' Get the form positions based upon the user specific data.
    If (ReadFormDataFromFile()) Then
        ' If the data was read from the file, set the form
        ' positions manually.
        _form1.StartPosition = FormStartPosition.Manual
        _form2.StartPosition = FormStartPosition.Manual

        _form1.Bounds = _form1Position
        _form2.Bounds = _form2Position
    End If

    ' Show both forms.
    _form1.Show()
    _form2.Show()
End Sub

Private Sub OnApplicationExit(ByVal sender As Object, ByVal e As EventArgs)
    ' When the application is exiting, write the application data to the
    ' user file and close it.
    WriteFormDataToFile()

    Try
        ' Ignore any errors that might occur while closing the file handle.
        _userData.Close()
    Catch
    End Try
End Sub

설명

경로가 없으면 다음 형식으로 만들어집니다.If a path does not exist, one is created in the following format:

기본 경로\CompanyName\ProductName\ProductVersionBase Path\CompanyName\ProductName\ProductVersion

이 경로에 저장 된 데이터에는 로밍에 사용 되는 사용자 프로필의 일부입니다.Data stored in this path is part of user profile that is enabled for roaming. 로밍 사용자 네트워크에 둘 이상의 컴퓨터에서 작동합니다.A roaming user works on more than one computer in a network. 사용자 프로필 로밍 사용자에 대 한 서버 네트워크에서 유지 되 고 사용자가 로그온 하면 시스템으로 로드 됩니다.The user profile for a roaming user is kept on a server on the network and is loaded onto a system when the user logs on. 로밍에 대 한 것으로 간주 하는 사용자 프로필에 대 한 운영 체제는 로밍 프로필을 지원 해야 하 고 사용 하도록 설정 해야 합니다.For a user profile to be considered for roaming, the operating system must support roaming profiles and it must be enabled.

일반적인 기본 경로 C:\Documents and Settings\username\Application Data.A typical base path is C:\Documents and Settings\username\Application Data. 이 경로 다를 수 있지만 Windows Forms 애플리케이션은 사용 하 여 배포 하는 경우 ClickOnceClickOnce합니다.This path will be different, however, if the Windows Forms application is deployed by using ClickOnceClickOnce. ClickOnceClickOnce 다른 모든 애플리케이션에서 격리 된 자체 애플리케이션 데이터 디렉터리를 만듭니다.creates its own application data directory that is isolated from all other applications. 자세한 내용은 로컬 및 ClickOnce 애플리케이션의 원격 데이터 액세스합니다.For more information, see Accessing Local and Remote Data in ClickOnce Applications.

적용 대상

추가 정보