1
A
回答
0
是的,這是可能的。
配置存儲在該位於以下位置的文件的My.Settings:
C:\ Users \ [用戶your_username] \應用程序數據\本地\ [應用發佈商] \ [應用程序的名稱] \ [app version#] \ user.config
我確定您可以以編程方式將目標應用程序的user.config文件的XML加載到您的應用程序中,對其進行調整並保存。
打開目標應用程序後,user.config文件將像正常一樣加載,並且您對XML所做的任何更改都會反映出來。
0
設置保存爲xml。默認情況下,文件名爲Settings.settings,位於Project Directory\My Project
。
在你的榜樣+其他設置,該文件可能看起來像這樣
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings"
CurrentProfile="(Default)" GeneratedClassNamespace="My"
GeneratedClassName="MySettings" UseMySettingsClassName="true">
<Profiles />
<Settings>
<Setting Name="SomeString" Type="System.String" Scope="User">
<Value Profile="(Default)">This is some string</Value>
</Setting>
<Setting Name="SomeOtherString" Type="System.String" Scope="User">
<Value Profile="(Default)">This is some other string</Value>
</Setting>
</Settings>
</SettingsFile>
您可以generate vb.net classes from the XML如果你有VS 2012或更高版本。我做到了,這裏是生成的類。 (如果你至少沒有VS 2012,你仍然可以使用微軟的XML Schema Definition Tool)。
<System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True, [Namespace]:="http://schemas.microsoft.com/VisualStudio/2004/01/settings"), _
System.Xml.Serialization.XmlRootAttribute([Namespace]:="http://schemas.microsoft.com/VisualStudio/2004/01/settings", IsNullable:=False)> _
Partial Public Class SettingsFile
Private profilesField As Object
Private settingsField() As SettingsFileSetting
Private currentProfileField As String
Private generatedClassNamespaceField As String
Private generatedClassNameField As String
Private useMySettingsClassNameField As Boolean
Public Property Profiles() As Object
Get
Return Me.profilesField
End Get
Set(value As Object)
Me.profilesField = value
End Set
End Property
<System.Xml.Serialization.XmlArrayItemAttribute("Setting", IsNullable:=False)> _
Public Property Settings() As SettingsFileSetting()
Get
Return Me.settingsField
End Get
Set(value As SettingsFileSetting())
Me.settingsField = value
End Set
End Property
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property CurrentProfile() As String
Get
Return Me.currentProfileField
End Get
Set(value As String)
Me.currentProfileField = value
End Set
End Property
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property GeneratedClassNamespace() As String
Get
Return Me.generatedClassNamespaceField
End Get
Set(value As String)
Me.generatedClassNamespaceField = value
End Set
End Property
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property GeneratedClassName() As String
Get
Return Me.generatedClassNameField
End Get
Set(value As String)
Me.generatedClassNameField = value
End Set
End Property
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property UseMySettingsClassName() As Boolean
Get
Return Me.useMySettingsClassNameField
End Get
Set(value As Boolean)
Me.useMySettingsClassNameField = value
End Set
End Property
End Class
<System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True, [Namespace]:="http://schemas.microsoft.com/VisualStudio/2004/01/settings")> _
Partial Public Class SettingsFileSetting
Private valueField As SettingsFileSettingValue
Private nameField As String
Private typeField As String
Private scopeField As String
Public Property Value() As SettingsFileSettingValue
Get
Return Me.valueField
End Get
Set(value As SettingsFileSettingValue)
Me.valueField = value
End Set
End Property
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property Name() As String
Get
Return Me.nameField
End Get
Set(value As String)
Me.nameField = value
End Set
End Property
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property Type() As String
Get
Return Me.typeField
End Get
Set(value As String)
Me.typeField = value
End Set
End Property
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property Scope() As String
Get
Return Me.scopeField
End Get
Set(value As String)
Me.scopeField = value
End Set
End Property
End Class
<System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True, [Namespace]:="http://schemas.microsoft.com/VisualStudio/2004/01/settings")> _
Partial Public Class SettingsFileSettingValue
Private profileField As String
Private valueField As String
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property Profile() As String
Get
Return Me.profileField
End Get
Set(value As String)
Me.profileField = value
End Set
End Property
<System.Xml.Serialization.XmlTextAttribute()> _
Public Property Value() As String
Get
Return Me.valueField
End Get
Set(value As String)
Me.valueField = value
End Set
End Property
End Class
有了這些類,您可以序列化和反序列化XML設置文件。當然,您可以使用xml序列化讀取和寫入設置文件。
這個完整的解決方案演示瞭如何編輯設置
' define the path to the settings file
Dim settingsPath = "C:\Users\username\AppData\Local\Temporary Projects\ConsoleApplication1\My Project\Settings.settings"
Dim serializer As New XmlSerializer(GetType(SettingsFile))
Sub Main()
Dim settingsObject As SettingsFile
' open the settings file for reading
Using sr As New StreamReader(settingsPath) ' deserialize the xml file to the settings object
settingsObject = CType(serializer.Deserialize(sr), SettingsFile)
End Using
Console.WriteLine("Available settings:") ' display the available settings
Console.WriteLine(
String.Join(Environment.NewLine, settingsObject.Settings.Select(
Function(s) String.Format("{0}: '{1}'", s.Name, s.Value.Value))))
Console.WriteLine("Enter a setting name to be modified...")
Dim settingNameToBeModified = Console.ReadLine()
Dim settingToBeModified =
settingsObject.Settings.
Where(Function(s) s.Name.ToUpper() = settingNameToBeModified.ToUpper()).Single()
Console.WriteLine(
"Enter a new value for {0} (old value: '{1}')",
settingToBeModified.Name, settingToBeModified.Value.Value)
Dim newValue = Console.ReadLine()
If EditSetting(settingToBeModified, newValue) Then
Console.WriteLine("Saved new setting!")
Else
Console.WriteLine("Couldn't find setting '{0}'", settingNameToBeModified)
End If
Console.WriteLine("Press enter to exit")
Console.ReadLine()
End Sub
Public Function EditSetting(settingObject As SettingsFileSetting, newValue As String)
Try
Console.WriteLine(
"Enter a new value for {0} (old value: '{1}')",
settingObject.Name, settingObject.Value.Value)
settingObject.Value.Value = newValue
Using sr As New StreamWriter(settingsPath) ' open the settings file again, for writing
serializer.Serialize(sr, settingObject) ' serialize the settings object to the xml file
End Using
Console.WriteLine("Saved new setting!")
Catch
Return False
End Try
End Function
相關問題
- 1. 如何從VB.NET中的應用程序中關閉另一個應用程序?
- 2. 使用iTunes應用程序,從另一個應用程序
- 3. 我該如何從一個應用程序調用另一個應用程序?
- 4. 從vb.net應用程序中的另一個應用程序調用方法
- 5. 從另一個應用程序更改應用程序的變量
- 6. 如何從另一個應用程序終止一個應用程序
- 7. 如何從另一個qt應用程序運行一個qt應用程序
- 8. Android - 如何從一個應用程序切換到另一個應用程序?
- 9. 從我的應用程序調用另一個應用程序
- 10. 從另一個應用程序調用應用程序
- 11. 從另一個應用程序調用應用程序
- 12. 如何從另一個Java應用程序使用NetBeans平臺應用程序
- 13. 從另一個應用程序的電話欄應用程序
- 14. 從我的應用程序打開另一個應用程序?
- 15. 如何從另一個應用程序調用處理程序?
- 16. 如何將C#應用程序設置從一個應用程序遷移到另一個應用程序?
- 17. 從另一個應用程序調用一個Angularjs應用程序的功能?
- 18. 從另一個應用程序調用一個應用程序的WebMethod?
- 19. 從一個Web應用程序VB.NET
- 20. 從一個應用程序調用會話到另一個應用程序
- 21. Nativescript - 從Nativescript應用程序啓動另一個應用程序
- 22. 從另一個Java應用程序啓動Java應用程序
- 23. 從另一個應用程序控制WPF應用程序
- 24. 從另一個java應用程序控制java應用程序
- 25. 從另一個應用程序啓動Java應用程序
- 26. 從另一個應用程序控制應用程序
- 27. 從另一個應用程序管理iPhone應用程序
- 28. 從另一個rcp應用程序啓動rcp應用程序
- 29. 從另一個應用程序啓動應用程序
- 30. 從另一個基本應用程序創建應用程序時更改應用程序標識
應用程序設置被設計成一個應用程序將加載只有它的設置,所以你不會是能夠做到這一點直通'My.Setings'。它也可能因部署方法而複雜化(XCopy vs OneClick)對於共享的套件類型配置,您可以自己保存數據,以便其他應用程序(而不僅僅是您的)可以訪問它們。 – Plutonix
你能否讓它更清楚一點......只是說出你說的幾個部分... :(#MyBad –
並且請在你的解釋中加上這個簡單的答案......(是的,如果可能的話,否則,如果不是的話) –