【发布时间】:2012-01-05 15:59:48
【问题描述】:
我正在开发一个应该读取 XML 文件的webpart。为此,我创建了一个类,其中 NodeValue() 方法应返回节点内的文本。如果使用控制台应用程序进行测试,这确实有效,但是当我将此(阅读器类和自定义 XML 文件)添加到我的 SharePoint 项目并尝试部署它时,我收到错误消息 Web Part error: File Not Found。我尝试更改文件属性,以便将其添加到编译版本,但我似乎仍然无法指定文件的路径。这是阅读器类:
using System;
using System.Reflection;
using System.IO;
using System.Xml;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OrgChartPart.WebPartCode
{
class ReadXml
{
public string FilePath { get; set; }
public ReadXml()
{
FilePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)+"\\LAYOUTS\\config.xml";
}
public string NodeValue(int pos)
{
if (pos <= 0)
return "invalid position!(this is not a node value)";
XmlTextReader textReader = new XmlTextReader(FilePath);
int counter = 0;
while (counter != pos)
{
textReader.Read();
if (textReader.NodeType.ToString() == "Text")
counter++;
}
return textReader.Value;
}
}
}
这是我在其中实例化此类以读取文件的 Web 部件代码的一部分:
StringBuilder sb = new System.Text.StringBuilder();
.......
string position = null, link_type = null, link_color = null,
node_alignment = null, node_fill = null, node_color_style = null, hyperlinks = null;
ReadXml readXml = new ReadXml();
sb.Append(@"
........
我不知道我是否在识别文件路径时遇到问题,还是需要提高权限才能访问它?或者,当解决方案部署时,目录结构发生了变化,所以我指定了错误的路径?你怎么看? 提前致谢
【问题讨论】:
标签: xml sharepoint web-parts