Reputation: 23
I wish to validate whether a file requires checking out in the library settings. I'm looking for a method that can check in my webservice if a particular file requires checking out.
Please give sample code or tell me the method name. I tried to use forcedcheckout
but it turned out that that method was just forcibly changing the settings.
Upvotes: 0
Views: 2268
Reputation: 4028
I would say, you can check if versioning is enabled on the library.
If yes than check if file is checked out using, if not than check out. Below is my code, u can customise it. Let me know if any doubts.
SPFolder sharepointfolder = web.GetFolder(SharepointfolderURL);
if (newFolder.RequiresCheckout)
{
SPFile fileOld = web.GetFile(sharepointfolder + "/" + name);
fileOld.CheckOut();
SPFile spfile = web.Folders.Add(SharepointfolderURL).Files.Add(name, fileStream, true);
spfile.Item[SPBuiltInFieldId.ContentTypeId] = customDocumentType.Id;
spfile.Item.SystemUpdate();
if (spfile.CheckedOutByUser.LoginName == @"SHAREPOINT\system")
{
spfile.CheckIn("System Checkin", SPCheckinType.MajorCheckIn);
}
}
Upvotes: 1