1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Newly added document listed as Draft with Published check mark

Newly added document listed as Draft with Published check mark

11 posts, 1 answered
  1. David
    David avatar
    34 posts
    Registered:
    26 Feb 2010
    29 Jul 2011
    Link to this post
    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"? 
  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    16 Aug 2017
    01 Aug 2011
    Link to this post
    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
    Answered
  3. David
    David avatar
    34 posts
    Registered:
    26 Feb 2010
    02 Aug 2011
    Link to this post
    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. 
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    05 Aug 2011
    Link to this post
    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
  5. David
    David avatar
    34 posts
    Registered:
    26 Feb 2010
    10 Aug 2011
    Link to this post
    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
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    16 Aug 2011
    Link to this post
    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
  7. David
    David avatar
    34 posts
    Registered:
    26 Feb 2010
    16 Aug 2011
    Link to this post
    I mentioned two methods. What about the other method - StorageProviderDecorator.ClearChunks ?  Is there a public method that is equivalent? 

    Thanks,
    David
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    18 Aug 2011
    Link to this post
    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
  9. David
    David avatar
    34 posts
    Registered:
    26 Feb 2010
    19 Aug 2011
    Link to this post
    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?
  10. Kristian
    Kristian avatar
    214 posts
    Registered:
    03 Jun 2010
    29 Sep 2011
    Link to this post
    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
  11. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    16 Aug 2017
    04 Oct 2011
    Link to this post
    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
11 posts, 1 answered