locked
[SP2007] New item in doc library RRS feed

  • Question

  • Hello,

    I need cancel the add of new items in a doc library while they're already in and with a status ="Valid" or ="Obsolete"..

    Have you an idea how shall i control this condition during the event?

    thanks


    http://nallerhand.free.fr >> Trucs & Astuces développement
    Monday, September 20, 2010 10:10 AM

Answers

  • Hi !
    You have to write a custom event receiver using Visual Studio and the SharePoint object model, overload the ItemAdding event, query the current document library to check if there's some other documents with the same name and the status column equals to "Valid" or "Obsolete".
    If there's some, you have to cancel the event with this code:

    properties.Cancel = true;
    properties.ErrorMessage = "You can not upload this file...";

    So, the ItemAdding event will be stopped.


    Giuseppe Marchi - SharePoint MVP - www.peppedotnet.it
    • Proposed as answer by Ginni Atul Sharma Monday, September 20, 2010 3:52 PM
    • Marked as answer by KeFang Chen Tuesday, September 28, 2010 8:41 AM
    Monday, September 20, 2010 10:30 AM

All replies

  • Hi !
    You have to write a custom event receiver using Visual Studio and the SharePoint object model, overload the ItemAdding event, query the current document library to check if there's some other documents with the same name and the status column equals to "Valid" or "Obsolete".
    If there's some, you have to cancel the event with this code:

    properties.Cancel = true;
    properties.ErrorMessage = "You can not upload this file...";

    So, the ItemAdding event will be stopped.


    Giuseppe Marchi - SharePoint MVP - www.peppedotnet.it
    • Proposed as answer by Ginni Atul Sharma Monday, September 20, 2010 3:52 PM
    • Marked as answer by KeFang Chen Tuesday, September 28, 2010 8:41 AM
    Monday, September 20, 2010 10:30 AM
  • yes I've already done it but no result.. itemAdding is not call :/
    http://nallerhand.free.fr >> Trucs & Astuces développement
    Monday, September 20, 2010 5:30 PM
  • Did you register the handler over your document library ?
    Giuseppe Marchi - SharePoint MVP - www.peppedotnet.it
    Tuesday, September 21, 2010 8:18 AM
  • Of course.

    I see it with columns manager and debug mode in visual studio. But when I deploy the event on the ItemUpdating method, I can debug it when I upload a new document in my library.

    Then, I have to find a way to make a difference between :

    - an upload overwriting a document with statut Valid or Obsolete to cancel it OR

    - if the document replace one with a different status, so it's ok.


    http://nallerhand.free.fr >> Trucs & Astuces développement
    Tuesday, September 21, 2010 8:53 AM
  • ok.
    if your handler starts well, you have to do a CAML query over the current list, to check if there's another file with the same filename of the one which is just added and check its status column.
    if the status column is valid or obsolate, you have to cancel the handler. otherwise, you don't have to do do nothing.

    Giuseppe Marchi - SharePoint MVP
    www.peppedotnet.it
    www.dev4side.com
    www.sharepointcommunity.it
    Twitter: @PeppeDotNet
    Monday, September 27, 2010 7:27 AM
  • Hi,

    CAML query use for getting existing value and to compare you have to use properties.AfterProperties["column"] to get current user provided new value.

    so you have both value..just compare it and if both values are matched then

    properties.Cancel = true;
    properties.ErrorMessage = "You can not upload this file...";

     

    let me know if you have any doubts...


    thanksArup MCTS - SharePoint

    Play Sudoku
    Monday, September 27, 2010 1:02 PM
  • Hi,

    Thanks for your reply.

    I 've done all of this but there is a new problem..

    If I modify one item wich is valid or obsolet, it cancel this action too because the code is in the event "itemUpdating" ..

    Is there a property I can use to know if the current item is going to be add in the list or if it is just a modification of one item in the list.

    Wednesday, October 6, 2010 9:01 AM
  • up... :$
    Monday, October 11, 2010 12:02 PM