Newly added document listed as Draft with Published check ma

Posted by Community Admin on 04-Aug-2018 16:07

Newly added document listed as Draft with Published check mark

All Replies

Posted by Community Admin on 29-Jul-2011 00:00

I used the sample code to create a new document in the Document Library. When it's completed, the document is listed as "Draft", but it has the green "Published" check mark. 

Here's my code:

var addedDocument = App.WorkWith()
   .DocumentLibrary(GetLiteratureLibrary().Id)
   .CreateDocument()
   .Do(d =>
      
         d.Title = "Test Document";
         d.Description = "Description for test document";
      )
   .CheckOut()
   .UploadContent(documentContentStream, fileExtension)
   .CheckInAndPublish()
   .SaveChanges();

I've attached a screenshot of the document status. Is there any way to set the document to "Published"? 

Posted by Community Admin on 01-Aug-2011 00:00

Hi David,

This is because the item has ContentLifeCycleStatus Live, but the WorkFLow state is not set to published (if you have an active workflow setting it directly to published would be against the workflow rules). However, if you don't use any workflow, then you can try the below sample, it will also set the ApprovalWorkflowState to Published:

var myDocument=  App.WorkWith()
               .DocumentLibrary(parentID)
               .CreateDocument()
                    .Do(d =>
                    
                        d.Title = documentName;
                        d.Description = description;
                         
                    )
                    .CheckOut()
                    .UploadContent(docFile.OpenRead(), docFile.Extension)
                    .CheckIn()
                    .Do(d =>
                        
                            d.ApprovalWorkflowState ="Published";
                        ).Publish()
                .SaveChanges();

Kind regards,
Boyan Barnev
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 02-Aug-2011 00:00

Thanks. That fixed the issue with creating a document. 

Now I'm trying to update the content of that document, and I'm getting an error. Here's the code:

App.WorkWith()
   .Document(docId)
   .Do(d =>
           
               d.Status = ContentLifecycleStatus.Master;
           )
   .CheckOut()
   .UploadContent(documentContentStream, fileExtension)
   .CheckIn()
   .Do(d =>
           
               d.ApprovalWorkflowState = "Published";
           )
   .Publish()
   .SaveChanges();

(The d.Status = ContentLifecycleStatus.Master; was necessary to check out the file.) 

I'm getting the error:

Telerik.OpenAccess.Exceptions.DataStoreException was unhandled by user code
  Message=Insert of '1719647903-6a7077a7-a8c9-4da8-b8f1-738530f104c5' failed: Telerik.OpenAccess.RT.sql.SQLException: String or binary data would be truncated.
The statement has been terminated.
   at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.execute()
   at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.execute()
   at OpenAccessRuntime.Relational.RelationalStorageManager.generateInserts(NewObjectOID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, CharBuf s, Object[] oidData, IntArray toUpdateIndexes)
INSERT INTO [sf_media_content] ([voa_class], [approval_workflow_state_], [approval_workflow_state_en], [approval_workflow_state_fr], [author_], [author_en], [author_fr], [id], [can_inherit_permissions], [chunk_size], [extension], [file_id], [inherits_permissions], [mime_type], [number_of_chunks], [ordinal], [parent_id], [total_size], [uploaded], [description_], [description_en], [description_fr], [title_], [title_en], [title_fr], [url_name_], [url_name_en], [url_name_fr], [allow_comments], [allow_track_backs], [app_name], [approve_comments], [content_id], [content_state], [date_created], [default_page_id], [draft_culture], [email_author], [expiration_date], [last_modified], [last_modified_by], [original_content_id], [ownr], [post_rights], [publication_date], [source_key], [status], [vrsion], [views_count], [visible], [votes_count], [votes_sum], [voa_version], [display_date], [parts_], [parts_en], [parts_fr]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
(set event logging to all to see parameter values) Telerik.OpenAccess.RT.sql.SQLException: String or binary data would be truncated.
The statement has been terminated.
   at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.execute()
   at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.execute()
   at OpenAccessRuntime.Relational.RelationalStorageManager.generateInserts(NewObjectOID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, CharBuf s, Object[] oidData, IntArray toUpdateIndexes)
  Source=Telerik.Sitefinity
  CanRetry=false
  StackTrace:
       at Telerik.Sitefinity.Data.TransactionManager.CommitTransaction(String transactionName)
       at Telerik.Sitefinity.Fluent.AnyContent.Implementation.Helpers.AllFacadesHelper.SaveChanges(AppSettings settings, IManager manager)
       at Telerik.Sitefinity.Fluent.AnyContent.Implementation.Helpers.AllFacadesHelper.SaveChanges(AppSettings settings)
       at Telerik.Sitefinity.Fluent.BaseFacadeWithManager.SaveChanges()
       at Telerik.Sitefinity.Fluent.BaseSingularFacade`3.SaveChanges()
       at Telerik.Sitefinity.Fluent.ContentFluentApi.BaseContentSingularFacade`3.SaveChanges()
       at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: Telerik.OpenAccess.RT.sql.SQLException
       Message=String or binary data would be truncated.
The statement has been terminated.
       Source=Telerik.OpenAccess.Adonet2
       Description=SQLState=;String or binary data would be truncated.
The statement has been terminated.
       ErrorCode=8152
       Number=8152
       StackTrace:
            at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.execute()
            at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.execute()
            at OpenAccessRuntime.Relational.RelationalStorageManager.generateInserts(NewObjectOID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, CharBuf s, Object[] oidData, IntArray toUpdateIndexes)
       InnerException: 

(etc...)

Any ideas?

I tried to "set event logging to all to see parameter values", but I cannot find anything about that. 

Posted by Community Admin on 05-Aug-2011 00:00

Hi David,

Here is a sample code that illustrates how to reupload an item

public void ReplaceDocument(Telerik.Sitefinity.Libraries.Model.MediaContent content, System.IO.Stream source)
      
          var fluent = App.WorkWith();
  
          //find if the document already exists by title, or introduce other business rule
          var facade = fluent.Documents().
              Where(d => d.Title == content.Title &&
                  d.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master
                  && d.Id != content.Id
                  &&
                  d.Parent.Id == content.Parent.Id //check if it the replaced document in the same album as prev. document
                  );
  
          int count = 0;
          facade.Count(out count);
  
          if (count > 0)
          
              //gets first document facade
              var firstDocumentFacade = facade.First();
              var oldFileId = firstDocumentFacade.Get().FileId;
  
              //change id to the new file id
              firstDocumentFacade
              .Do(s =>
                  
                      s.FileId = content.FileId;
                      //update extension
                      s.Extension = content.Extension; //file extension
                        
                  );
  
              var documentItem = firstDocumentFacade.Get();
     
              //update content data
              base.UploadDataOnly(documentItem, source);
  
              firstDocumentFacade.SaveAndContinue();
  
              content.FileId = Guid.NewGuid();
              //delete newly inserted document
              base.Delete((Document)content);
              //clear chunks of old media item
              this.StorageProviderDecorator.ClearChunks(oldFileId);
          
          else
          
              base.UploadDataOnly(content, source);
          
      

This is a sample from the data provider so you can create an instance of the LibrariesDataProvider and call UploadDataOnly method.

Best wishes,
Ivan Dimitrov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 10-Aug-2011 00:00

Hi Ivan,

Thanks for the code example. I couldn't find a good example for creating an instance of LibrariesDataProvider, so I tried this:

var libProvider = LibrariesManager.GetManager().Provider;

I then found that UploadDataOnly and StorageProviderDecorator are protected members. I noticed I could use the Upload method instead - would that be sufficient? 

I couldn't find a good substitute for StorageProviderDecorator.ClearChunks. There is a method ClearNotReferencedMediaContentChunks, but I'm clear how to use it. 

Thanks again,
David

Posted by Community Admin on 16-Aug-2011 00:00

Hello David,

It turned out that UploadDataOnly is marked as a private method. The Upload method calls UploadDataOnly so you can try use it.

All the best,
Ivan Dimitrov
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 16-Aug-2011 00:00

I mentioned two methods. What about the other method - StorageProviderDecorator.ClearChunks ?  Is there a public method that is equivalent? 

Thanks,
David

Posted by Community Admin on 18-Aug-2011 00:00

Hi David,

This is no more used. It is handled by OpenAccessBlobStorageProvider which in its basis inherits from the base class for data providers.

Regards,
Ivan Dimitrov
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 19-Aug-2011 00:00

I started implementing the code example for updating the document. However, before I could get that far, I ran into a new error when adding a document. 

I took my original code:

var addedDocument = App.WorkWith()
   .DocumentLibrary(GetLiteratureLibrary().Id)
   .CreateDocument()
   .Do(d =>
      
         d.Title = "Test Document";
         d.Description = "Description for test document";
      )
   .CheckOut()
   .UploadContent(documentContentStream, fileExtension)
   .CheckInAndPublish()
   .SaveChanges();

and I'm now getting this error:

System.Reflection.TargetInvocationException was unhandled by user code
  Message=Exception has been thrown by the target of an invocation.
  Source=Unity_ILEmit_DynamicClasses
  StackTrace:
       at DynamicModule.ns.Wrapped_OpenAccessVersionDataProvider_69ca9c411da049498c34a6288f6a4cfa.CreateVersion(Object versionedItem, Guid itemId, Boolean isPublished)
       at Telerik.Sitefinity.Versioning.VersionManager.CreateVersion(Object versionedItem, Guid itemId, Boolean isPublished)
       at Telerik.Sitefinity.Fluent.ContentFluentApi.BaseContentSingularFacadeWithLifeCycle`3.CreateVersion(TContent item, ContentUIStatus uiStatus)
       at Telerik.Sitefinity.Fluent.ContentFluentApi.BaseTempFacade`4.CheckIn(Boolean excludeVersioning)
       at Telerik.Sitefinity.Fluent.ContentFluentApi.BaseTempFacade`4.CheckIn()
       at Telerik.Sitefinity.Fluent.ContentFluentApi.BaseTempFacade`4.CheckInAndPublish()
......
       StackTrace:
            at DynamicModule.ns.Wrapped_OpenAccessLibrariesProvider_228750b7f4ac4c21803491ddcde9e215.GetItemUrl(ILocatable item)
            at Telerik.Sitefinity.Modules.GenericContent.ContentManagerBase`1.GetItemUrl(ILocatable item)
            at Telerik.Sitefinity.Abstractions.AppSettings.GetItemUrl(ILocatable locatable)
            at Telerik.Sitefinity.Libraries.Model.MediaContent.get_MediaUrl()
            at Telerik.Sitefinity.Libraries.Model.MediaContent.get_Url()
       InnerException: 

I've upgraded to SiteFinity 4.2 since this thread started. Is this something due to the 4.2 upgrade?

Posted by Community Admin on 29-Sep-2011 00:00

The fluent api to publish items programmaticly only 'pretends' to work. If i publish a document item with your suggested answer Boyan then the document item in the backend does have the checkmark icon and says it is published sure. But, the actions drop down says I can still publish the document, which I would expect to say unpublish!

This is a problem for me because while I have a control that users can / upload / download and edit document properties such as title / description. If the item isn't published correctly then non-administrators cannot download the item (navigating to the mediaurl).

I got around this by switching to the native api. But this then goes back to the problem of the Checkmark with Draft text posted originally in this thread. Im using v 4.2.1650.0

Posted by Community Admin on 04-Oct-2011 00:00

Hi Kristian,

Thank you for bringing our attention to this. I have logged a bug concerning this functionality, and we'll be working on providing a fix for it in the upcoming releases. In the meantime please accept our apologies for the inconvenience caused, we'd recommend you to use the native API sample instead.

Greetings,
Boyan Barnev
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed