Chinaunix首页 | 论坛 | 博客
  • 博客访问: 767901
  • 博文数量: 372
  • 博客积分: 10063
  • 博客等级: 中将
  • 技术积分: 4220
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-24 11:36
文章分类

全部博文(372)

文章存档

2012年(372)

分类: 系统运维

2012-04-24 21:50:10

为一个演讲大会做了一个list供用户上传照片(实现了固定图片大小和格式的限制), 通过sharepoint网站可以直接查看所有演讲者(speaker)的照片。用户又希望可以把所有人的照片一并下载到本地,并以演讲者的姓名命名。查 了一下msdn,为这个功能写了个小工具,代码很简单,通过lists.asmx提供的web service来实现,大体如下:

复制代码
using (SharePoint_WS_Lists.Lists listWS = new SharePoint_WS_Lists.Lists()) { listWS.Url = ; listWS.Credentials = System.Net.CredentialCache.DefaultCredentials; listWS.UseDefaultCredentials = true; XmlDocument xmlDoc = new System.Xml.XmlDocument(); XmlNode ndListItems = null; XmlNamespaceManager nsmgr; XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element, "Query", ""); XmlNode ndViewFields = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", ""); XmlNode ndQueryOptions = xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", ""); ndQueryOptions.InnerXml = "FALSE" + "TRUE"; ndViewFields.InnerXml = ""; ndQuery.InnerXml = "" + "0"; try { ndListItems = listWS.GetListItems("Photo Upload", null, ndQuery, ndViewFields, null, ndQueryOptions, null); //MessageBox.Show(ndListItems.OuterXml); } catch (System.Web.Services.Protocols.SoapException ex) { MessageBox.Show("Message:\n" + ex.Message + "\nDetail:\n" + ex.Detail.InnerText + "\nStackTrace:\n" + ex.StackTrace); } nsmgr = new XmlNamespaceManager(ndListItems.OwnerDocument.NameTable); nsmgr.AddNamespace("s", "uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"); nsmgr.AddNamespace("dt", "uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"); nsmgr.AddNamespace("rs", "urn:schemas-microsoft-com:rowset"); nsmgr.AddNamespace("z", "#RowsetSchema"); string speaker; int iCount = 0; string sTest = ""; foreach (XmlNode xmlNode in ndListItems.SelectNodes("rs:data/z:row", nsmgr)) { iCount++; try { speaker = xmlNode.Attributes["ows_Speaker"].Value; int strLastIndx = speaker.LastIndexOf(@";#"); speaker = speaker.Substring(strLastIndx + 2); XmlNode node = listWS.GetAttachmentCollection("Photo Upload", xmlNode.Attributes["ows_ID"].Value); DataSet ds = new DataSet(); using (XmlNodeReader reader = new XmlNodeReader(node)) { ds.ReadXml(reader); } DataTable dtAttachment = ds.Tables[0]; for (int iCnt = 0; iCnt <= dtAttachment.Rows.Count - 1; iCnt++) { string sourceUrl = Convert.ToString(dtAttachment.Rows[iCnt][0]); if (sourceUrl.ToLower().IndexOf(".jpg") > 0) { } else { //int test = iCnt;///root/Datasets/Dataset[contains(@Pattern, 'xyz')] continue; } //strLastIndx = sourceUrl.LastIndexOf(@"/"); //string FileName = sourceUrl.Substring(strLastIndx + 1); using (WebClient client = new WebClient()) { client.UseDefaultCredentials = true; byte[] response = client.DownloadData(sourceUrl); FileStream fStream = new FileStream(@"C:\share\photo\" + speaker + ".jpg", FileMode.Create, FileAccess.ReadWrite); fStream.Write(response, 0, response.Length); fStream.Close(); } } } catch (Exception ex) { string *** = ex.Message; continue; } } } }
复制代码

 

阅读(775) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~