Using the MOSS Imaging web service to download images(Imaging.asmx)

Posted: May 30, 2008 in MOSS 2007

Using the MOSS Imaging web service to download images(Imaging.asmx)

 

                I recently had the opportunity to utilize the Imaging web service to scan for images, analyze meta-data and download images from a MOSS farm. It was not too bad to do but one of the major issues I had was finding resources with samples. So, I thought I would rectify the lack of information out there with some samples of my own. 

                First to find the asmx, it is located at “/_vit_bin/Imaging.asmx” from any site within your portal. Many of the functions (such as listing image libs will be done relative to the site you reference the asmx from). Without further ado, here are some samples for tasks I needed to accomplish.

Note:

          Imaging() class is a web reference to imagining.asmx

          The Download call natively returns XML so yo uneed to run it through a conversion to byte

          If you need to get a reference on the Imagine web service check this on out on MSDN:

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

 

 

Task 1: Getting a List of Image libs on a given site

public static XmlNode GetPicLibListingXML(string imagingServiceURL)

 {

                Imaging wsImaging = new Imaging();

                wsImaging.UseDefaultCredentials = true;

                wsImaging.Url = imagingServiceURL;

 

                XmlNode xnPicLibs = wsImaging.ListPictureLibrary();

 

                return xnPicLibs;

   }

 

Sample return 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/&quot; />

 

Task 2: Listing Images in a given library

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;

   }

 

Task 3: Download Image(s)

private const string ATTR_FILENAME = "name";

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

 

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;

        }

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s