以编程方式从库中读取

时间:2010-12-01 19:40:16

标签: c# sharepoint-2007 xslt

我有一个名为“xsl library”的文档库,里面有一堆xsl ...我需要从那里读取一个文件(任何一个),所以我可以用它来转换一个呈现webpart的xml ... webpart中的布局由xsl决定......我该怎么做?

备注:环境 - > Sharepoint 2007

2 个答案:

答案 0 :(得分:2)

所以看起来你需要一些服务器端代码:

SPFile xslFile = SPContext.Current.Web.GetFile("/myWeb/myXlsLibrary/myXsl.xsl"); 
Stream xslStream = xslFile.OpenBinaryStream(); 

然后你编写类似于上面Vlad提供的代码进行转换。

有关所用功能的更多信息,请参阅MSDN - http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.getfile.aspxhttp://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfile.openbinarystream.aspx

答案 1 :(得分:0)

XslCompiledTransform proc = new XslCompiledTransform();

proc.Load(XmlReader.Create(new StringReader(stringWithXsltStylesheetCode)));

XmlDocument result = new XmlDocument();
using (XmlWriter xw = result.CreateNavigator().AppendChild())
{
   proc.Transform(inputXmlDocument, null, xw);
   xw.Close();
}