Michael's profileMike's RavingsBlogLists Tools Help

Blog


    May 30

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

    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/" />

     

    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/";

     

    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;

            }

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://gourangaland.spaces.live.com/blog/cns!135E00A751103A8A!270.trak
    Weblogs that reference this entry
    • None