我有一個VS 2008 Web部件項目 - 這個項目是一個web.config文件: 是這樣的:從SharePoint Web部件訪問的web.config
<?xml version="1.0"?>
<configuration>
<connectionStrings/>
<system.web>
<appSettings>
<add key="MFOwner" value="Blah" />
</appSettings>
…….
在我的網絡的一部分,我想在appSetting部分訪問值: 我已經嘗試了所有下面的代碼,每個返回null:
string Owner = ConfigurationManager.AppSettings.Get("MFOwner");
string stuff1 = ConfigurationManager.AppSettings["MFOwner"];
string stuff3 = WebConfigurationManager.AppSettings["MFOwner"];
string stuff4 = WebConfigurationManager.AppSettings.Get("MFOwner");
string stuff2 = ConfigurationManager.AppSettings["MFowner".ToString()];
我試過這個代碼,我發現:
NameValueCollection sAll;
sAll = ConfigurationManager.AppSettings;
string a;
string b;
foreach (string s in sAll.AllKeys)
{
a = s;
b = sAll.Get(s);
}
,並通過它踩在調試模式 - 即把事情一樣:
FeedCacheTimer
FeedPageURL
FeedXsl1
ReportViewerMessages
沒有從任何未來在我的web.config文件中... .may可以是sharepoint本身的配置文件嗎?我如何訪問web.config(或任何其他類型的配置文件!)本地到我的web部分?
感謝,
菲爾Ĵ
@philj:格式化代碼,在編輯器中選擇它並按下Control-K。否則,它最好看起來很可怕。 – 2010-06-15 01:53:17