开发者

Application Data Folder and Company Name With Underscores

My VB.NET 2008, .NET 3.5 application is using an app.config with settings defined as User. As expected, it created the folder:

C:\Documents and Settings\<user>\Local Settings\Application Data\<company name>\

In this folder are the sub-folders for the application to store the user settings. However, the folder of the company name has underscores:

C:\Documents and Settings\<user>\Local Settings\Application Data\This__Is_My_Company\

None of the other folders in this directory have underscores, and it looks stupid. Is there any way to tell the application to create the folder without underscores in the name?

UPDATE (26-Mar-2012):

This appears to be more of an issue on Windows 7 (at least - could be XP too but I'm already off XP). If I use the .NET Framework to create 开发者_如何学Cthe folder if it doesn't exist ...

Const TEST_FOLDER_PATH As String = "{0}\{1}"

Dim appDataFolderPath As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
Dim companyName As String = My.Application.Info.CompanyName

MessageBox.Show(String.Format(TEST_FOLDER_PATH, appDataFolderPath, companyName))

... then it will produce a folder path without underscores in the company name. Oddly enough, .NET 3.5 still creates its own folder in \AppData\Local\ for the user's app.config settings with underscores.

I end up with one folder with underscores for the user's app.config data, and one folder without underscores so I can tell our third-party spell checker where to store the user-dictionary.txt file. Looks like I'll have to hard-code the company name in order to keep everything to one folder, or live with two folders. Wonderful ...


The LocalFileSettingsProvider class is responsible by default for storing config settings in .NET. It seems to put in underscores for all managed applications by default - I see it in several apps in my local settings directory. If you are really concerned about the name, you could:

  1. Use the technique described in Changing the .NET application configuration file name question.
  2. Create your own SettingsProvider and have it use the right filename. This sounds like re-inventing the wheel though.
  3. Use camel-case for your company name.


i would use reflector to inspect the code thats putting the _ in there in the first place and see if its got any ifs in it


Does your company name have spaces in it? I know that spaces in folder names are perfectly acceptable, but it may be that VB 2008 is trying to be a little bit too clever and "saving you from yourself".

If that turns out to be the case, have a look in the My Project\Settings.designer.vb file. You may find the code that generates the name in there and be able to modify it manually. I would check myself, but I can't lay my hands on a copy of VB 2008 until tomorrow. :-)


In the AssemblyInfo.cs what does it have for you company name? Does it have the underscores?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜