SharePoint开发记录
1.一个正式发布的网站不要使用超过一个模板页.
2.尽量使用CSS去控制页面的布局,而不是使用Layout
3.通过xstl改写ContentQueryMain.xsl 可以适当的控制CQWP输出的HTML代码,
如果你想去掉外层的Table:<table class="s4-wpTopTable"><table>,这里有一篇老外写的文章可以帮助你: URL:https://www.nothingbutsharepoint.com/sites/eusp/Pages/Customizing-the-HTML-code-of-a-Content-Query-Web-Part.aspx
但是我通过半天的尝试,发现如果你的webpart是嵌套在WebPartZone中,你会发现你的那篇文章描述的方法并不管用,也就是你要去掉外层包的Table就不能把WebPart放到WebPartZone中。
4. 如果你有一大段的文章内容,包含有HTML标签,你想用XSLT去掉标签的话:
1 <!--作用:移出文章中的HTML标签 By CQF--> 2 <xsl:template name="removeHtmlTags"> 3 <xsl:param name="html"/> 4 <xsl:choose> 5 <xsl:when test="contains($html, '<')"> 6 <xsl:value-of select="substring-before($html, '<')"/> 7 <!-- Recurse through HTML --> 8 <xsl:call-template name="removeHtmlTags"> 9 <xsl:with-param name="html" select="substring-after($html, '>')"/> 10 </xsl:call-template> 11 </xsl:when> 12 <xsl:otherwise> 13 <xsl:value-of select="$html"/> 14 </xsl:otherwise> 15 </xsl:choose> 16 </xsl:template>
使用方法如下:
<!--移出HTML标签后,保存文章内容到变量中 --> <xsl:variable name="contentText"> <xsl:call-template name="removeHtmlTags"> <xsl:with-param name="html" select="@Content" /> </xsl:call-template> </xsl:variable>
(这是在我真实的SharePoint项目中使用的.)
5.根据QueryString过滤在webpart的过滤条件中选择ID,值为 [PageQueryString:newsID] ,当你打开该webpart所在页码并在url中附上参数:newsID,就可以实现过滤!
6. camlquery 查询list:
class List_getItemsExample { static void Main() { string siteUrl = "http://MyServer/sites/MySiteCollection"; ClientContext clientContext = new ClientContext(siteUrl); Web site = clientContext.Web; List targetList = site.Lists.GetByTitle("Announcements"); CamlQuery query = new CamlQuery(); query.ViewXml = "<View><Query><Where><Contains><FieldRef Name='Title'/><Value Type='Text'>announce</Value></Contains></Where></Query></View>"; ListItemCollection collListItem = targetList.GetItems(query); clientContext.Load(collListItem,'Include(Title,Author)'); //优化:只加载Title和Author列,可加快加载速度 clientContext.ExecuteQuery(); if (collListItem.Count == 0) { Console.WriteLine("No items containing 'announce' found."); } else { Console.WriteLine("Items containing 'announce' found:\n"); foreach (ListItem targetListItem in collListItem) Console.WriteLine(targetListItem["Title"]); } }
}
7.如何获取LookUp字段的值?
SPFieldLookupValue lookupField = new SPFieldLookupValue(item["TechSkills"].ToString());
string lookUpValue = lookupField.LookupValue;