Search code examples
c#sharepoint-2007

Unable to publish files in SharePoint


When I publish a file from code

byte[] fileBytes = objItem.File.OpenBinary();
string DestinationURL = string.Format(@"{0}/{1}", objDestinationFolder.Url, objItem.File.Name);

//Copy the file.
SPFile objDestinationFile = objDestinationFolder.Files.Add(DestinationURL, fileBytes, true);
objDestinationFile.Update();
objDestinationFile.Publish(string.Format("File Copied from {0}", objItem.Url));

I get an error message which says

 You can only publish, unpublish  documents in a minor version enabled list 

I checked the permissions of the list and it has "Create major and minor (draft) versions" checked. Any ideas?

EDIT

If I check in the file by calling the CheckIn method

objDestinationFile.CheckIn(string.Format(@"File Copied from {0}/{1}", objItem.Web.Url, objItem.Url));

everything works fine


Solution

  • I think that a file has to be checked in first, and then it can be published.

    So in your case it might be possible, that in the settings of your list 'checkout required' is activated. Which means that if you upload a document, it is checked out first.