다음을 통해 공유


Application.LocalUserAppDataPath 속성

로밍 사용자가 아닌 로컬 사용자의 응용 프로그램 데이터 경로를 가져옵니다.

네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)

구문

‘선언
Public Shared ReadOnly Property LocalUserAppDataPath As String
‘사용 방법
Dim value As String

value = Application.LocalUserAppDataPath
public static string LocalUserAppDataPath { get; }
public:
static property String^ LocalUserAppDataPath {
    String^ get ();
}
/** @property */
public static String get_LocalUserAppDataPath ()
public static function get LocalUserAppDataPath () : String

속성 값

로밍 사용자가 아닌 로컬 사용자의 응용 프로그램 데이터 경로입니다.

설명

로컬 사용자는 로그온한 시스템에 사용자 프로필이 저장되어 있는 사용자를 나타냅니다. 경로가 없으면 다음 형식으로 만들어집니다.

Base Path\ CompanyName \ ProductName \ ProductVersion

일반적인 기본 경로는 C:\Documents and Settings\username\Local Settings\Application Data입니다.

예제

다음 코드 예제에서는 두 개의 폼을 표시하고 두 개의 폼이 모두 닫히면 응용 프로그램을 종료합니다. 응용 프로그램이 시작되어 종료되면 각 폼의 위치가 기억됩니다. 이 예제에서는 UserAppDataPath 속성을 사용하여 사용자에 대한 응용 프로그램 데이터를 저장하지만,LocalUserAppDataPath를 대신 사용할 수 있습니다.

MyApplicationContext 클래스는 ApplicationContext에서 상속되고 각 폼이 닫히는 시기를 추적하며 두 폼이 모두 닫힌 경우 현재 스레드를 종료합니다. 이 클래스는 사용자에 대한 각 폼의위치를 저장합니다. 폼 위치 데이터는 UserAppDataPath에 의해 결정되는 위치에 만들어지는 Appdata.txt 파일에 저장됩니다. ApplicationContext가 주어지는 경우 Main 메서드는 **Application.Run(context)**을 호출하여 응용 프로그램을 시작합니다.

이 코드는 ApplicationContext 클래스 개요에 표시된 예제에서 인용됩니다. 간결함을 위해 일부 코드는 표시되지 않습니다. 전체 코드 목록을 보려면 ApplicationContext를 참조하십시오.

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
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 {}
}
   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.add_ApplicationExit(new EventHandler(
        this.OnApplicationExit));
    try {
        // Create a file that the application will store 
        // user specific data in.
        userData = new FileStream(Application.get_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.add_Closed(new EventHandler(OnFormClosed));
    form1.add_Closing(new CancelEventHandler(OnFormClosing));
    formCount++;
    form2 = new AppForm2();
    form2.add_Closed(new EventHandler(OnFormClosed));
    form2.add_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.set_StartPosition(FormStartPosition.Manual);
        form2.set_StartPosition(FormStartPosition.Manual);
        form1.set_Bounds(form1Position);
        form2.set_Bounds(form2Position);
    }

    // Show both forms.
    form1.Show();
    form2.Show();
} //MyApplicationContext

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 (System.Exception exp) {
    }
} //OnApplicationExit

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

참고 항목

참조

Application 클래스
Application 멤버
System.Windows.Forms 네임스페이스