Referencing Documents in the library by ID (and deleting them)
Hello Telerik staff,
using (var sf = Telerik.Sitefinity.App.WorkWith()) var doc = sf.Document().CreateNew().Do(item => item.Parent = sf.DocumentLibraries().Where(l => l.Title == "Konstruktionen").Get().FirstOrDefault(); item.Title = uploadedFile.GetName(); ).CheckOut(); Document document = doc.UploadContent(uploadedFile.InputStream, uploadedFile.GetExtension()).CheckInAndPublish().Get(); //Store the id in a variable of type Guid guid = document.Id;using (var sf = Telerik.Sitefinity.App.WorkWith()) sf.Documents().Where(c => c.Id == guid).Delete().SaveChanges();Hello David,
Thank you for getting back to us.
Can you please let us know which version of Sitefinity you are using? I have tried this with Sitefinity 4.0 Beta 2 Build 685 and the item is properly deleted. Bellow is the code I used:
App.WorkWith().Documents().Where(d => d.Title == "Document Title").Delete().SaveChanges();App.WorkWith().Document(guid).Delete().SaveChanges();Hi Radoslav!
App.WorkWith().Documents().Where(c => c.Title == "document.pdf").Delete().SaveChanges();Hello David,
There are changes in the Fluent API and this issue cannot be reproduced by us in the internal builds. I prepared a sample demo for you.
control template
<asp:Button runat="server" ID="Trigger" Text="click to execute" />void Trigger_Click(object sender, EventArgs e) var document = App.WorkWith().Documents().Get().FirstOrDefault(); if (document != null && document.Id != Guid.Empty) var itemID = document.Id; var alertText = @"<script type='text/javascript'>" + "alert('" + itemID + "');" + "</script>"; this.Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "itm1", alertText); App.WorkWith().Documents().Where(doc => doc.Id == itemID).Delete().SaveChanges(); else var alertText = @"<script type='text/javascript'>" + "alert(\" There is no items in the library\");" + "</script>"; this.Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "itm1", alertText);