0

I am working on a requirement event receiver generates page content into Microsoft Word and PDF using a third party DLL. Once the generation is completed I need to upload it to document library.

This happens on ItemUpdated and code works fine when the doc or pdf files are not in the library but when they are created and I have to update them it throws an error.

 ex = {"The file \"http://www-mylab.com/en/home/Documents/James-bond_1033.pdf\" is not checked out.  You must first check out this document before making changes."}

   web.Files.Add(wordFileUrl, wordStream, true);
cyberhicham
  • 495
  • 1
  • 10
  • 24

2 Answers2

0

Easiest to turn of the "Require Checkout" setting on your document library versioning settings.

Otherwise you will have to call the CheckInFile and CheckOutFile members of the SharePoint Lists webservice.

Nat
  • 14,175
  • 5
  • 41
  • 64
  • No need for the webservice if you're using the Server object model as the question suggests. `SPFile f = web.GetFile(wordFileUrl); f.CheckOut();` should do the trick. – ErikE Jan 15 '13 at 01:45
  • Yeah, there needs to be more info because the question does not suggest use of the SharePoint OM to me... In which case *much* more help is required. – Nat Jan 15 '13 at 02:02
  • Doesn't web.Files.Add(url,stream,boolean) look like http://msdn.microsoft.com/en-us/library/ms412937(v=office.12).aspx ? – ErikE Jan 17 '13 at 20:14
0

It looks like you're using SharePoint's server object model.

SPFile f = web.GetFile(wordFileUrl); 
f.CheckOut(); 

web.Files.Add(wordFileUrl, wordStream, true);

f.Checkin("new version");

should do the trick

ErikE
  • 857
  • 8
  • 18