| Michael's profileMike's RavingsBlogLists | Help |
|
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:
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; } TrackbacksThe trackback URL for this entry is: http://gourangaland.spaces.live.com/blog/cns!135E00A751103A8A!270.trak Weblogs that reference this entry
|
|
|