从图片库中检索图像 - REST

时间:2011-11-07 20:56:56

标签: sharepoint rest sharepoint-2010

我正在寻找一些关于使用REST API从图片库中检索图像(实际文件,而不是URL)的建议或示例。

感谢您的任何意见。

1 个答案:

答案 0 :(得分:1)

任务1:获取给定站点上的图像库列表

public static XmlNode GetPicLibListingXML(string imagingServiceURL)
 {

                Imaging wsImaging = new Imaging();
                wsImaging.UseDefaultCredentials = true;
                wsImaging.Url = imagingServiceURL;
                XmlNode xnPicLibs = wsImaging.ListPictureLibrary();

                return xnPicLibs;
   }

示例返回XML:

<Library name="{3C1D52F5-5387-490A-9A2D-A9C99A208C00}" title="Tech Images" guid="3c1d52f5-5387-490a-9a2d-a9c99a208c00" url="Tech Images" xmlns="http://schemas.microsoft.com/sharepoint/soap/ois/" />

任务2:在给定库中列出图像

public static XmlNode GetImageFileListing(string imagingServiceURL, string imageFileLibraryName)

 {
      Imaging wsImaging = new Imaging();
      ImageInfo curImageInfo = new ImageInfo();
       wsImaging.UseDefaultCredentials = true;
       wsImaging.Url = imagingServiceURL;
       XmlNode xnListItems = wsImaging.GetListItems(imageFileLibraryName, "");

       return xnListItems;
   }

任务3:下载图像

private const string ATTR_FILENAME = "name";

private const string FILENAMESPACEURI = "http://schemas.microsoft.com/sharepoint/soap/ois/";

public static bool DownloadImageFiles(string imagingServiceURL, string imageFileLibraryName, string[] fileNames, string saveToFolder)

 {
        Imaging wsImaging = new Imaging(); 
        wsImaging.UseDefaultCredentials = true;
        wsImaging.Url = imagingServiceURL;

       XmlElement parent = (XmlElement)wsImaging.Download(imageFileLibraryName, string.Empty, fileNames, 0, true);

       XmlNodeList files = parent.GetElementsByTagName("File", FILENAMESPACEURI);

        foreach (XmlNode file in files)
        {
             if (Directory.Exists(saveToFolder) == false)
            {
                 Directory.CreateDirectory(saveToFolder);
              }

           byte[] fileBytes = Convert.FromBase64String(file.InnerText);

            using (FileStream fs = File.OpenWrite(saveToFolder + file.Attributes[ATTR_FILENAME].Value))
             {
                    BinaryWriter writer = new BinaryWriter(fs);
                    writer.Write(fileBytes);
                    writer.Close();
                }
          }  
          return true;
        }

注意:

  • Imaging()类是对imagining.asmx
  • 的Web引用
  • 下载调用本身返回XML,因此您无法通过转换为字节
  • 来运行它
  • 如果您需要获取有关Imagine Web服务的参考,请在MSDN上查看:

http://msdn.microsoft.com/en-us/library/imaging.imaging.aspx

源:

http://gourangaland.wordpress.com/2008/05/30/using-the-moss-imaging-web-service-to-download-imagesimaging-asmx/