locked
spfile.delete gives file is checked out or locked for editing exception. RRS feed

  • Question

  • hello friends,

    i have developed a custom webservice wherein i try to move the spfile within a document library between two folders. I tried with spfile.delete but it gives me exception.

     

    System.Runtime.InteropServices.COMException (0x8107090E): The file is a user http://tsnt4-test/espis/Lists/TSAkJKDocuments/154545445-342423/abc.doc DMTSIT \ spospisilova checked out or locked for editing.

    even when i try to use spfile.copyTo and spfile.moveTo it gives me the same exception

    i used the following two approaches

      //Approach 1
                                //web.AllowUnsafeUpdates = true;
                                //SPFile sptempfile = collFiles[FileName];
                                //byte[] tempbytearray = { 1 };
                                //sptempfile.SaveBinary(tempbytearray);
                                //sptempfile.Delete();
                                //collFiles.Folder.Update();
                                //web.Update();

                                // Approach 2 if there is a lock.
                                web.AllowUnsafeUpdates = true;
                                SPFile sptempfile = collFiles[FileName];
                                byte[] tempbytearray = { 1 };
                                sptempfile.SaveBinary(tempbytearray);
                                SPListItem splitem = sptempfile.Item;
                                splitem.Delete();
                                collFiles.Folder.Update();
                                web.Update();

     

    Amit


    • Edited by Mike Walsh FIN Wednesday, November 3, 2010 12:57 PM plz reply asap - removed, don't push
    Monday, October 25, 2010 1:30 PM

Answers

  •  

    you need to checkin the document by using below mentioned code:
    //check file status
     if(spFile.CheckOutStatus != SPFile.SPCheckOutStatus.None)

    {
      spFile.CheckIn(string.Empty);

    }

    • Edited by Mike Walsh FIN Wednesday, November 3, 2010 12:59 PM sig removed - don't ask people to mark your posts
    • Marked as answer by Wayne Fan Friday, November 5, 2010 5:56 AM
    Wednesday, November 3, 2010 11:35 AM

All replies

  • You need to run the SPFile.CheckIn method to check in the file before making changes to it (including updates and deletion)
    • Edited by Mike Walsh FIN Wednesday, November 3, 2010 12:58 PM sig removed - don't ask people to mark your posts
    Monday, October 25, 2010 5:42 PM
  • i tried that but it doesnt work.
    Tuesday, October 26, 2010 4:18 AM
  •  

    you need to checkin the document by using below mentioned code:
    //check file status
     if(spFile.CheckOutStatus != SPFile.SPCheckOutStatus.None)

    {
      spFile.CheckIn(string.Empty);

    }

    • Edited by Mike Walsh FIN Wednesday, November 3, 2010 12:59 PM sig removed - don't ask people to mark your posts
    • Marked as answer by Wayne Fan Friday, November 5, 2010 5:56 AM
    Wednesday, November 3, 2010 11:35 AM