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
开发者_Go百科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
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.
I got this error even though minor versions were enabled on the library. The reason was I had added a draft file to a module without the Type="GhostableInLibrary"
attribute. Once I corrected this the draft file could be published by my feature receiver.
精彩评论