在asp.net中将XML绑定到网格视图

问题描述:

Hello Techies

我将sharepoint文档库带入了asp.net应用程序,从那开始我要显示特定文件的版本历史记录
如果选择特定文件,则意味着我使用版本Web服务获取版本历史记录,因此我将版本历史记录获取为XML格式.现在我希望它绑定在Grid中.

XML在下面

< list id ="{918044DD-4034-4804-862D-91DA49D93299}" xmlns ="http://schemas.microsoft.com/sharepoint/soap/"/>
< versioning enabled ="1" xmlns ="http://schemas.microsoft.com/sharepoint/soap/"/>
< settings url ="http://admin:10085/_layouts/LstSetng.aspx?List = {918044DD-4034-4804-862D-91DA49D93299}" xmlns ="http://schemas.microsoft.com/sharepoint/soap /"/>
<结果版本="@ 2.2" url ="http://admin:10085/DocumentLibrary/New Text Document(2).txt" created ="11/10/2011 3:31 PM" createdBy ="ADMIN \ administrator "size =" 25评论=" xcvbxc"xmlns =" http://schemas.microsoft.com/sharepoint/soap/"/>
<结果版本="1.0" url ="http://admin:10085/_vti_history/512/DocumentLibrary/New Text Document(2).txt" created ="creating =" 11/9/2011 7:54 PM"createdBy =" ADMIN \ administrator"size =" 25"comments =""xmlns =" http://schemas.microsoft.com/sharepoint/soap/"/>
<结果版本="2.1" url ="http://admin:10085/_vti_history/1025/DocumentLibrary/New Text Document(2).txt" created ="creating =" 11/10/2011 3:31 PM"createdBy =" ADMIN \ administrator"size =" 25"comments =""xmlns =" http://schemas.microsoft.com/sharepoint/soap/"/>


请帮助我解决此问题....

Hello Techies

I brought the sharepoint document library into asp.net application, From that i want to show the version history of a particular file
If i select the particular file means i get the version history using versions webservice, I got the version history as a XML format. now i want it to bind in Grid.

The XML Is below

<list id="{918044DD-4034-4804-862D-91DA49D93299}" xmlns="http://schemas.microsoft.com/sharepoint/soap/" />
<versioning enabled="1" xmlns="http://schemas.microsoft.com/sharepoint/soap/" />
<settings url="http://admin:10085/_layouts/LstSetng.aspx?List={918044DD-4034-4804-862D-91DA49D93299}" xmlns="http://schemas.microsoft.com/sharepoint/soap/" />
<result version="@2.2" url="http://admin:10085/DocumentLibrary/New Text Document (2).txt" created="11/10/2011 3:31 PM" createdBy="ADMIN\administrator" size="25" comments="xcvbxc" xmlns="http://schemas.microsoft.com/sharepoint/soap/" />
<result version="1.0" url="http://admin:10085/_vti_history/512/DocumentLibrary/New Text Document (2).txt" created="11/9/2011 7:54 PM" createdBy="ADMIN\administrator" size="25" comments="" xmlns="http://schemas.microsoft.com/sharepoint/soap/" />
<result version="2.1" url="http://admin:10085/_vti_history/1025/DocumentLibrary/New Text Document (2).txt" created="11/10/2011 3:31 PM" createdBy="ADMIN\administrator" size="25" comments="" xmlns="http://schemas.microsoft.com/sharepoint/soap/" />


Please help me to sort out this problem....

您必须先将Xml数据转换为DataTable并将该DataTable对象绑定到GrideView;
You have to Convert the Xml data to DataTable first and bind that DataTable object to GrideView;
DataTable dt = new DataTable();
dt.ReadXml(@"filepath.xml");
GridView1.DataSource = dt;
GridView1.DataBind();


当您右键单击asp.net页中的gridview控件时,它会要求您提供源,您也可以在那里选择xml文件格式. ..jus试试吧
when u right click the gridview control in the asp.net page it ll ask for the source u can also choose the xml file form there...jus try it


解决方案在

版本objVersions = new Versions();
objVersions.Url = ConfigurationManager.AppSettings ["SharepointVersionService"];
objVersions.Credentials = CreateCredentials();
XmlNode结果= objVersions.GetVersions(FileName);
如果((结果!= null)& Result.InnerXml.Length> 0)
{
XmlTextReader objXmlTextReader =新的XmlTextReader(Result.OuterXml,XmlNodeType.Element,null);
DataSet objDataSet =新的DataSet();
objDataSet.ReadXml(objXmlTextReader);
Gridhistory.DataSource = objDataSet.Tables [3] .DefaultView;
Gridhistory.DataBind();

}
the solution is below

Versions objVersions = new Versions();
objVersions.Url = ConfigurationManager.AppSettings["SharepointVersionService"];
objVersions.Credentials = CreateCredentials();
XmlNode Result = objVersions.GetVersions(FileName);
if ((Result != null) & Result.InnerXml.Length > 0)
{
XmlTextReader objXmlTextReader = new XmlTextReader(Result.OuterXml, XmlNodeType.Element, null);
DataSet objDataSet = new DataSet();
objDataSet.ReadXml(objXmlTextReader);
Gridhistory.DataSource = objDataSet.Tables[3].DefaultView;
Gridhistory.DataBind();

}