NerdyHearn
Home
Blog

Contact
Mailing List

Software

Active Directory Products
Object Compare
Permission Compare

IPhone Products
Calls To Calendar
SMS To CSV
SMS To Gmail
Voicemail To Gmail

Sites
DocuTerminal
How Long For Me
My Music To Me
SaveMySerials
TypeCount

Blog
Twitter

NerdyHearn - Blog


<< Back To All Blogs

Using MOSS and WSS SharePoint Workflow to Resize Images in an Image Library

Thursday, May 14th, 2009

It is often a request that image libraries have all of their image widths or heights normalized when they are uploaded to a SharePoint Image Library.
SharePoint does not natively include this functionality, so workflow is necessary to resolve the issue.

Image resizing is out of the scope of this blog post, and I have a class that I have used for a long time to achieve resizing. For the case of this blog post which
is going to be short, I will leave out the details of resizing an image, maintaining aspect ratio, etc.

On to the code:

// workflowProperties it the property set for workflow that you would have defined as
// a SPWorkflowActivationProperties object at the beginning of your workflow
// Item is specific to the item in workflow, File is the file item associated with the image library item
Resizer resizer = new Resizer(workflowProperties.Item.File.OpenBinaryStream());
resizer.Width = 1000;

// My Resize method will alter the image and return a stream of the data
Stream returned = resizer.Resize();

// The File supports a SaveBinary method which can take a stream in this case, but also a byte array
workflowProperties.Item.File.SaveBinary(returned);

// Update the item and you are done
workflowProperties.Item.File.Update();

// Make sure you clean up your stream
ms.Close();

Pretty straight-forward, but took me some time and digging to get to the bottom of the File.

Resizin' Tom Out.

Tags

SharePoint CSharp

Related Blogs

SharePoint RPC: Corrupted Binary Files
SharePoint Browser 1 Released!
Deploying Reporting Services WebParts to SharePoint WSS and MOSS
Fixing SharePoint error Log with "Preserving template record"
Receiving "The specified file is not a valid spreadsheet or contains no data" when importing to Office 365

Comments

Currently no comments.

Add A Comment

Name:


URL:


Email Address: (not public, used to send notifications on further comments)


Comments:



Enter the text above, except for the 1st and last character:


NerdyHearn - Latest tech news relating to C#, ASP.NET, SharePoint, PHP, general development, and more. DocuTerminal - Online Filing Cabinet solution. Scan, search and archive your paper documents. SaveMySerials - Protect yourself from theft, fire, natural disasters and more by recording your serial numbers My Music To Me - Stream your subsonic music collection to your Sonos wireless system TypeCount - Count how often you type across different computers! ServrTrackr - Monitor your SSL certificates, website uptime, and DNS configurations