locked
How to Update Metadata with Picture in a Picture Library RRS feed

  • Question

  • Hi,

    I have a picture library to store users images. Each image is associated with certain metadata. We need to upload images to the picture into the picture library with the meta data. Ex: Each picture has a user id associated with it. When the picture is uploaded, we want to set the user id value also.

    Could anyone help me on how to acheive this programatically.

    Let me know if more details are required.


    Raj
    • Moved by Matt Wilson - Systems Engineer Monday, June 7, 2010 6:29 PM (From:Microsoft Online: SharePoint Online)
    • Moved by Mike Walsh FIN Tuesday, June 8, 2010 9:25 AM programmatically questions go to the Programming forum. Please don't send them to the General forum, it ought to be clear that isn't the place for them (From:SharePoint - General Question and Answers and Discussion (pre-SharePoint 2010))
    Thursday, June 3, 2010 8:27 AM

Answers

  • Hi,

    This can be acheived in a lot simpler way. Check out the small code snippet below,

    Step 1:

    Define a Hash table with a key value pair, and add the values to the key's as below,

    //Create a hash table
    Hashtable pictureProperties = new Hashtable();
    
    //Add values to hash table
    pictureProperties.Add("UserId", loginUserId);
    

    Step 2:

    Create a picture library object, and add the following snippet to upload images to the picture library with the hash code

    //Upload the new image and associate the userid
    //fuUserImage is the file upload control name and ohPictureLibrary is the SPPictureLibrary object
    Stream streamImage = fuUserImage.PostedFile.InputStream;
    ohPictureLibrary.RootFolder.Files.Add("c:\image.bmp", streamImage, pictureProperties);

    Step 3:

    Thats it... your all set to go. Its as simple.


    Raj
    • Marked as answer by Ganti Monday, June 21, 2010 2:29 PM
    Monday, June 21, 2010 2:28 PM

All replies

  • Hi,

    Cannot give you a piece of code or anything but I think you need to develop an SPItemEventReceiver. On the ItemAdded event you somehow need to retract the metadata (userid) and add it to the userid column.

    HTH.

     

    PS: check this starting article: http://blogs.msdn.com/b/brianwilson/archive/2007/03/05/part-1-event-handlers-everything-you-need-to-know-about-microsoft-office-sharepoint-portal-server-moss-event-handlers.aspx

    • Marked as answer by Aaron Han - MSFT Friday, June 11, 2010 9:34 AM
    • Unmarked as answer by Ganti Monday, June 21, 2010 1:59 PM
    Tuesday, June 8, 2010 8:42 AM
  • Hi,

    This can be acheived in a lot simpler way. Check out the small code snippet below,

    Step 1:

    Define a Hash table with a key value pair, and add the values to the key's as below,

    //Create a hash table
    Hashtable pictureProperties = new Hashtable();
    
    //Add values to hash table
    pictureProperties.Add("UserId", loginUserId);
    

    Step 2:

    Create a picture library object, and add the following snippet to upload images to the picture library with the hash code

    //Upload the new image and associate the userid
    //fuUserImage is the file upload control name and ohPictureLibrary is the SPPictureLibrary object
    Stream streamImage = fuUserImage.PostedFile.InputStream;
    ohPictureLibrary.RootFolder.Files.Add("c:\image.bmp", streamImage, pictureProperties);

    Step 3:

    Thats it... your all set to go. Its as simple.


    Raj
    • Marked as answer by Ganti Monday, June 21, 2010 2:29 PM
    Monday, June 21, 2010 2:28 PM