XML To Linq 读取Sharepoint列表中的附件列信息

通过页面查看,列表附件信息列的内容如下:

var x = @"<div class='ExternalClass9936DCD1F074427B891D09CFCEFC2AB6'><p><a href='/sites/twf/wml/费用明细1123.doc'>"                     +"<img class='ms-asset-icon ms-rtePosition-4' alt='费用明细1123.doc' src='/sites/twf/_layouts/images/icdoc.png' />费用明细1123.doc</a></p>"                    

+"<p><a href='/sites/twf/wml/费用明细1123-2.doc'><img class='ms-asset-icon ms-rtePosition-4' alt='费用明细1123-2.doc' src='/sites/twf/_layouts/images/icdoc.png' />费用明细1123-2.doc</a></p><p> </p></div>";      

使用Linq To XML解析数据,如下:      

var element = XElement.Parse(x);            

var links = element.Descendants("a");//获取所有a链接          

foreach (var link in links)            

{                

  var fileName = link.Value;//获取文件名             

  var fileUrl = link.Attribute("href").Value;//获取链接地址                

  Console.WriteLine("{0} :{1}", fileName, fileUrl);                

  Console.WriteLine(result);            

}

posted on 2013-11-24 08:36  thankyou  阅读(253)  评论(0编辑  收藏  举报