打算用MOSS做一个新闻发布类的网站,思路是把发布页面保存到页面库中,添加新闻分类字段,根据分类读取。
今天设计了一个母版页,修改了一下主页面,通过用户控件的形式从页面库读取内容显示。
总结:1保存用户控件时,需要选择UTF格式。需要注册安全控件,需要修改<trust>设置level为Full才可以。
2需要把dll复制到bin目录。
3把用户控件复制到相关目录,编写一个批处理部署用户控件。需要编写Feature文件。
明天继续……
相关代码:需要引用Microsoft.SharePoint.dll
string[] pFields = { "ID", "主题"};
private DataTable _sourceDataTable;
private DataTable ListToDataTable()
{
SPSite site = new SPSite("http://moss:7003");
SPWeb web = site.RootWeb;
web.AllowUnsafeUpdates = true;
SPList list = web.Lists["政务论坛"];
SPQuery qry = new SPQuery();
qry.Query = "<Where><Neq><FieldRef Name='Title' />" +
"<Value Type='Text'>a</Value></Neq></Where>";
SPListItemCollection lists = list.GetItems(qry);
DataTable dt = new DataTable();
for (int intI = 0; intI < pFields.Length; intI++)
{
DataColumn col = new DataColumn(pFields[intI]);
dt.Columns.Add(col);
}
this._sourceDataTable = dt;
foreach (SPListItem item in lists)
{
try
{
DataRow row = _sourceDataTable.NewRow();
for (int intI = 0; intI < pFields.Length; intI++)
{
if (item[pFields[intI]] != null)
{
if (intI == 0)
{
//Object colType = _sourceDataTable.Columns[pFields[intI]].DataType;
row[pFields[intI]] = item[pFields[intI]];
}
else
{
//if (list.Fields[pFields[intI]].FieldValueType.ToString() == "Microsoft.SharePoint.SPFieldUserValue")
//{
// //
//}
//else
//{
Object colType = _sourceDataTable.Columns[pFields[intI]].DataType;
row[pFields[intI]] = item[pFields[intI]];
//}
}
}
}
_sourceDataTable.Rows.Add(row);
}
catch
{
}
}
return this._sourceDataTable;
}
feature.xml
<?xml version="1.0" encoding="utf-8"?>
<Feature Id="aa929aff-4602-4d7f-a501-b80ac9a4bb32" Title="用户控件集" Description="用户控件方案" Scope="Site" xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="UControls.xml" />
</ElementManifests>
</Feature>
用户控件xml
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Control Id="xinwen" Sequence="50" ControlSrc="~/_CONTROLTEMPLATES/xinwen.ascx">
</Control>
<Control Id="zuixinwenjian" Sequence="50" ControlSrc="~/_CONTROLTEMPLATES/zuixinwenjian.ascx">
</Control>
<Control Id="luntanredian" Sequence="50" ControlSrc="~/_CONTROLTEMPLATES/luntanredian.ascx">
</Control>
</Elements>