Tell me more ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I've been trying to add a watermark to files as they are uploaded to SharePoint. I tried using several events: ItemAdding, ItemUpdating, ItemCheckedIn.

In ItemUpdating and ItemCheckedIn the file is already in the DB. so I can add a watermark - but it's just a waste of DB read/write (The whole file is written, then I read it, then I re-save it to the db).

the ItemAdding event looks good, it does rise before the content is saved to the DB, but I do not have the content itself (SPItemEventProperties doesn't have any "content" attribute or something similar)

share|improve this question

2 Answers

up vote 2 down vote accepted

You can access the content from the ItemAdding event by using Request.Files property of the context. Try something like this :

HttpFileCollection files = HttpContext.Current.Request.Files;  
    foreach (String key in files.Keys)   
    {  
        if (collection[key].ContentLength > 0)   
        {  
           Stream stream = files[key].InputStream;  
           string filePath = files[key].FileName;  
        }  
    } 

For more info, read this post.

share|improve this answer

Have you tried the ItemAdded event instead? This fires after the item has finished being added to the library.

share|improve this answer
The real questions is - where do I get the content from in the ItemAdded event. Let's say I'm uploading a file to a document library, in the ItemAdded event, where can I see its content to add the water mark? – Roy Reznik Jul 26 '12 at 12:49
You should be able to get everything you need from properties.ListItem.File (msdn.microsoft.com/en-us/library/…) – Dave Wise Jul 26 '12 at 13:31
Checked it out - it's just like ItemCheckingIn and ItemUpdating - the file is already in the DB at this point, which means I'm doing extra read & rewrite for every file. that's a huge performance hit. – Roy Reznik Jul 26 '12 at 13:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.