2011-12-03 142 views
0

在我的C#項目,我有一個用戶級範圍的設定,我想使之成爲新用戶的默認值在設計時設置的文件夾路徑(如果我我沒有錯)。如何設置默認應用程序路徑值的用戶範圍設置

我想要的默認值設置爲用戶應用程序數據文件夾中的一個。我在設置中鍵入什麼值?我在解決方案資源管理器中雙擊它時引用了MSVS Settings.settings UI(不確定它是什麼)。

值應該是一個被返回,例如,Application.UserAppDataPath

(請連同我的其他問題閱讀:C# difference between Environment.SpecialFolders and Application folders爲我應該用什麼路徑)

謝謝!

UPDATE

隨着shf301的回答,我走了進去settings.designer.cs和這樣做:

[global::System.Configuration.UserScopedSettingAttribute()] 
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 
[global::System.Configuration.DefaultSettingValueAttribute("")] 
public string LogFolder { 
    get { 
     return ((string)(this["LogFolder"])) ?? System.Windows.Forms.Application.LocalUserAppDataPath; 
    } 
    set { 
     this["LogFolder"] = value; 
    } 
} 
+0

我會考慮分拆到這兩個問題 –

+0

我不知道實際。因爲我需要知道要設置哪個AppData路徑。 – Jake

回答

3

你不是什麼關鍵進入設置,因爲你可以不知道用戶的AppData文件夾。保留默認值空,在你的代碼中使用的設置,如果設置未設置(空或空字符串),然後使用Application.UserAppDataPath否則使用用戶的設置。

例如:

public static string GetUserPath() 
{ 
    string path = Settings.Default.UserPath; 
    if (string.IsNullOrEmpty(path)) 
     path = Application.UserAppDataPath; 
    return path; 
} 
+0

其實這可以直接完成的VS生成的設置類,但設計師總是每次我在設計師編輯恢復我的代碼回生成的版本。另一個悲傷的臉。 – Jake