Application.LocalUserAppDataPath プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)


ローカル ユーザーとは、ユーザー プロファイルが格納されているシステムにログオンしたユーザーのことです。パスが存在しない場合は、次の形式で作成されます。
ベース パス\ CompanyName \ ProductName \ ProductVersion
通常、ベース パスは C:\Documents and Settings\username\Local Settings\Application Data になります。

2 つのフォームを表示し、両方のフォームが閉じられたときにアプリケーションを終了するコード例を、次に示します。アプリケーションの開始時と終了時に、各フォームの位置が記憶されます。この例では、UserAppDataPath プロパティを使用してユーザーのアプリケーション データを格納していますが、代わりに LocalUserAppDataPath を使用することもできます。
MyApplicationContext クラスは、ApplicationContext の継承クラスで、各フォームがいつ閉じられたのかを追跡し、両方のフォームが閉じられたときに現在のスレッドを終了します。このクラスは、ユーザーの代わりに各フォームの位置を格納します。フォームの位置データは、Appdata.txt という名前のファイルに格納されます。このファイルは、UserAppDataPath で指定された場所に作成されます。Main メソッドは、Application.Run(context) を呼び出すことにより、ApplicationContext を指定してアプリケーションを起動します。
このコードは、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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からApplication.LocalUserAppDataPath プロパティを検索する場合は、下記のリンクをクリックしてください。

- Application.LocalUserAppDataPath プロパティのページへのリンク