Application.LocalUserAppDataPath プロパティ

定義

ローカルで非ローミング ユーザーのアプリケーション データのパスを取得します。Gets the path for the application data of a local, non-roaming user.

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

プロパティ値

ローカルで非ローミング ユーザーのアプリケーション データのパス。The path for the application data of a local, non-roaming user.

次のコード例では、2つのフォームを表示し、両方のフォームが閉じられたときにアプリケーションを終了します。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 プロパティを使用してユーザーのアプリケーションデータを格納する方法を示していますが、代わりに LocalUserAppDataPath を使用することもできます。Although this example demonstrates using the UserAppDataPath property to store application data for the user, the LocalUserAppDataPath can be used instead.

@No__t-0 クラスは ApplicationContext から継承され、各フォームが閉じられたときに追跡を続け、両方がである場合は現在のスレッドを終了します。The MyApplicationContext class 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. フォーム位置データは、UserAppDataPath によって決定された場所に作成される Appdata.txt という名前のファイルに格納されます。The form position data is stored in a file titled Appdata.txt that is created in the location determined by UserAppDataPath. @No__t-0 メソッドは、ApplicationContext を指定してアプリケーションを起動するために Application.Run(context) を呼び出します。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

注釈

ローカルユーザーとは、ユーザーがログオンしたシステムにユーザープロファイルが格納されているユーザーのことです。A local user is one whose user profile is stored on the system on which the user logged on. パスが存在しない場合は、次の形式で作成されます。If a path does not exist, one is created in the following format:

ベースパス\ @ no__t @ no__t @ no__t @ no__t-5 @ no__t のようになります。Base Path\CompanyName\ProductName\ProductVersion

一般的なベースパスは C:\documents and と設定 @ no__t-0username\Local Settings\Application Data です。A typical base path is C:\Documents and Settings\username\Local Settings\Application Data. ただし、Windows フォームアプリケーションが 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.

適用対象