How do I delete files attached with media entity in drupal 8.4.2?

Background:

drupal 8.4.2

custom media solution

Issue

I can not delete files permanently which created as media entity.

Reproduce

  1. Created an image media entity.
  2. /admin/content/files claims status permanent and used in 2 places.
  3. After deleting newly created media entity from UI /admin/content/media.
  4. /admin/content/files says status permanent and used in 1 places.

Even cron run after 6 hours (as described in file settings) file still exist on the server.

Is there any safest or best way to delete those unused file permanently?

Exchange Server – (permanently) delete mails from database

We have a problem with very large OST files of outlook. What we do is archiving the mails from the Exchange Server with a 3rd party software and delete them from the Exchange server afterwards.

Nonetheless the OST file size stays the same.

Do I really need to put the server in Maintenence mode (I have a technet article that details that over like 20 steps, or is there a faster method to accomblish that task?

Created Insert Update Delete Application on single page MVC

Hi I have created the on Application on MVC which make Select, Insert, Update and Delete in single page and I need to make it optimise. Please help me out.

I have created 2 partial page one for grid and another to submit data and I had called that partial pages into single View

Index.cshtml page layout is as below

@model WebApplication1.Models.Employee @{     ViewBag.Title = "Index";     Layout = "~/Views/Shared/_Layout.cshtml"; } <!DOCTYPE html> @section Scripts {     @Scripts.Render("~/bundles/jqueryval") } <html> <head>     <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />     <link href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap.min.css" rel="stylesheet" />     <link rel="stylesheet" href="//cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/e8bddc60e73c1ec2475f827be36e1957af72e2ea/build/css/bootstrap-datetimepicker.css" />     <meta name="viewport" content="width=device-width" />     <title>Create</title> </head> <body>     <div class="register_form full_width_reg">         @using (Html.BeginForm("Insertdata", "Employee", FormMethod.Get, new { @class = "form-horizontal", @id = "insertform", role = "form", enctype = "multipart/form-data" }))         {             <div id="addupdate"></div>         }     </div>     <div id="grid">     </div> </body> </html> @*<script src="https://code.jquery.com/jquery-3.3.1.js"></script>*@ <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script> <script src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment-with-locales.js"></script> <script type="text/javascript" src="//cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/e8bddc60e73c1ec2475f827be36e1957af72e2ea/src/js/bootstrap-datetimepicker.js"></script> <script>     $  (document).ready(function () {         $  .ajax({             type: "GET",             url: "/Employee/GetAddUpdate",             contentType: "application/json; charset=utf-8",             dataType: "html",             success: function (response) {                 if (response != null) {                     $  ("#addupdate").html(response);                     $  ('#datetimepicker1').datetimepicker();                     $  .validator.unobtrusive.parse("#insertform");                 } else {                     alert("Something went wrong");                 }             },             failure: function (response) {                 alert(response.responseText);             },             error: function (response) {                 alert(response.responseText);             }         });         bindgrid();     });      function bindgrid() {         $  .ajax({             type: "GET",             url: "/Employee/Getpartialdata",             contentType: "application/json; charset=utf-8",             dataType: "html",             success: function (response) {                 if (response != null) {                     $  ("#grid").html(response);                                          $  ('#example').DataTable({                         "order": [[0, "desc"]]                     });                  } else {                     alert("Something went wrong");                 }             },             failure: function (response) {                 alert(response.responseText);             },             error: function (response) {                 alert(response.responseText);             }         });     }      function insert() {         if ($  ("#txtname").val() == '' || $  ("#txtemail").val() == '' || $  ("#datetimepicker7").val() == '' || $  ("#designationid").val() == ''             || $  ("#txtsalary").val() == '' || $  ("#designationid").val() == '') {             $  ("#validate").click();             return false;         }         $  .ajax({             type: "GET",             url: "/Employee/Insertdata",             contentType: "application/json; charset=utf-8",             dataType: "json",             data: $  ("#insertform").serialize(),             success: function (response) {                 bindgrid();             },             failure: function (response) {                 alert(response.responseText);             },             error: function (response) {                 alert(response.responseText);             }         });     } </script> 

_AddUpdateData.cshtml is my partial page from where I used to Add and Update the data

@model WebApplication1.Models.Employee @Html.HiddenFor(m => m.empid) @Html.ValidationSummary(true) <h3>Register as a Student</h3> <hr /> <div class="hidden"></div>  <div class="form-group col-md-6 col-sm-6">     <div class="row">         <label class="col-md-4 control-label" for="Name">Name</label>         <div class="col-md-8">             @Html.EditorFor(model => model.empname, new { htmlAttributes = new { @class = "form-control", id = "txtname", placeholder = "Name" } })             @Html.ValidationMessageFor(model => model.empname)         </div>     </div> </div> <div class="form-group col-md-6 col-sm-6">     <div class="row">         <label class="col-md-4 control-label" for="Campus">Designation</label>         <div class="col-md-8">             @Html.DropDownListFor(model => model.designationid, Model.AvailableDesig, new { @class = "form-control" })             @Html.ValidationMessageFor(model => model.designationid)         </div>     </div> </div> <div class="clearfix"></div> <div class="form-group col-md-6 col-sm-6">     <div class="row">         <label class="col-md-4 control-label" for="Phone">Email Address</label>         <div class="col-md-8">             @Html.EditorFor(model => model.empemail, new { htmlAttributes = new { @class = "form-control", id = "txtemail", placeholder = "Email Address" } })             @Html.ValidationMessageFor(model => model.empemail)         </div>     </div> </div> <div class="form-group col-md-6 col-sm-6">     <div class="row">         @Html.LabelFor(m => m.empsalary, new { @class = "col-md-4 control-label" })         <div class="col-md-8">             @Html.EditorFor(model => model.empsalary, new { htmlAttributes = new { @class = "form-control", id = "txtsalary", placeholder = "Salary" } })             @Html.ValidationMessageFor(model => model.empsalary)          </div>     </div> </div> <div class="clearfix"></div>  <div class="form-group col-md-6 col-sm-6">     <div class="row">         @Html.LabelFor(m => m.date, new { @class = "col-md-4 control-label" })         <div class="col-md-8">             @Html.EditorFor(m => m.date, new { htmlAttributes = new { @class = "form-control input-group date", id = "datetimepicker1", placeholder = "Date" } })             @Html.ValidationMessageFor(model => model.date)         </div>     </div> </div>  <div class="form-group col-md-6 col-sm-6">     <div class="row">         @Html.LabelFor(m => m.gender, new { @class = "col-md-4 control-label" })         <div class="col-md-8">             @Html.Label("Male")             @Html.RadioButtonFor(m => m.gender, "Male")             @Html.Label("Female")             @Html.RadioButtonFor(m => m.gender, "Female")             @Html.ValidationMessageFor(model => model.gender)         </div>     </div> </div> <div class="form-group col-md-6 col-sm-6">     <div class="row">         <div class="col-md-offset-4 col-md-10">             <input type="submit" id="validate" class="btn btn-default btn-browse" value="Add" style="display:none;" />             <input type="button" id="submitfilteration" onclick="return insert();" class="btn btn-default btn-browse" value="Add" />         </div>     </div> </div>  

_PartialGrid.cshtml is my another Partial View where we can show all added data

@model IList<WebApplication1.Models.Employee>      <table id="example" class="table table-striped table-bordered" style="width:100%">         <thead>             <tr>                 <th>Id</th>                 <th>Name</th>                 <th>Email</th>                 <th>Gender</th>                 <th>Designation</th>                 <th>Salary</th>                 <th>Date</th>                 <th>Edit</th>                 <th>Delete</th>             </tr>         </thead>         <tbody>             @foreach (var item in Model)             {              <tr>                 <td>@item.empid</td>                 <td>@item.empname</td>                 <td>@item.empemail</td>                 <td>@item.gender</td>                 <td>@item.name</td>                 <td>@item.empsalary</td>                 <td>@item.date</td>                 <td>                     <input type="button" id="Editbtn" onclick="Editdata('@item.empid')" class="btn btn-default btn-browse" value="Edit" />                 </td>                 <td>                     <input type="button" id="deletebutton" onclick="Delete('@item.empid');" class="btn btn-default btn-browse" value="Delete" />                 </td>             </tr>             }                    </tbody>     </table> <script>     function Delete(id) {               $  .ajax({             url: '/Employee/Delete',             dataType: "html",             type: "POST", // You can use GET             contentType: 'application/json; charset=utf-8',             cache: false,             data: JSON.stringify({                 'id': id             }),             success: function (data) {                                bindgrid();              },             error: function (xhr) {                 console.log(request);                            }         });     }     function Editdata(id) {         $  .ajax({             url: '/Employee/Edit',             dataType: "html",             type: "POST", // You can use GET             contentType: 'application/json; charset=utf-8',             cache: false,             data: JSON.stringify({                 'id': id             }),             success: function (data) {                 $  ("#addupdate").html(data);                 $  .validator.unobtrusive.parse("#insertform");                                alert('success');             },             error: function (xhr) {                 console.log(request);                 // alert("Some error");             }         });     }     function bindgrid() {         $  .ajax({             type: "GET",             url: "/Employee/Getpartialdata",             contentType: "application/json; charset=utf-8",             dataType: "html",             success: function (response) {                 if (response != null) {                     $  ("#grid").html(response);                     $  ('#example').DataTable();                 } else {                     alert("Something went wrong");                 }             },             failure: function (response) {                 alert(response.responseText);             },             error: function (response) {                 alert(response.responseText);             }         });     } </script> 

EmployeeController.cs is my controller

namespace WebApplication1.Controllers {      public class EmployeeController : Controller     {         PracmvcEntities db = new PracmvcEntities();                public ActionResult Index()         {             Employee emp = new Employee();             emp.AvailableDesig = GetDesig();             return View(emp);         }                       [HttpGet]         public ActionResult Insertdata(Employee model)         {             bool gender = false;             if (model.empid == null)             {                                 if (model.gender == "Male")                 {                     gender = true;                 }                 db.insertemployeedata(model.empname, gender, model.designationid, model.empemail, model.empsalary, model.date);                 db.SaveChanges();                 return Json("success", JsonRequestBehavior.AllowGet);             }             //edit                        if (model.gender == "Male")             {                 gender = true;             }             db.updateemployeedata(model.empid,model.empname, gender, model.designationid, model.empemail, model.empsalary, model.date);             db.SaveChanges();             return Json("success", JsonRequestBehavior.AllowGet);         }          [HttpGet]         public ActionResult GetAddUpdate()         {             Employee emp = new Employee();             emp.AvailableDesig = GetDesig();             return PartialView("_AddUpdateData", emp);         }         [HttpGet]         public ActionResult Getpartialdata()         {             List<Employee> emp = db.selectemployeedata(0).Select(e => new Employee             {                 empid = e.empid,                 empname = e.empname,                 empsalary = Convert.ToDecimal(e.empsalary),                 empemail = e.empemail,                 gender = e.gender.ToString(),                 name = db.designations.Where(a => a.id == e.designationid).FirstOrDefault().name,                 id=e.id,                 date=e.date             }).ToList();             return PartialView("_PartialGrid", emp);         }         public IList<SelectListItem> GetDesig()         {             // This comes from database.                    var desig = db.selectemployeeedesignation()                 .Select(x => new SelectListItem { Text = x.name, Value = x.id.ToString() })                 .ToList();             desig.Insert(0, new SelectListItem { Text = "--Please Select--", Value = "" });             return desig;         }         [HttpPost]         public ActionResult Edit(int id)         {             Employee emp = db.selectemployeedata(id).Select(e => new Employee             {                 empid = e.empid,                 empname = e.empname,                 empsalary = Convert.ToDecimal(e.empsalary),                 empemail = e.empemail,                 gender = e.gender.ToString()=="True"? "Male" : "Female",                 name = db.designations.Where(a => a.id == e.designationid).FirstOrDefault().name,                 id = e.id,                 date = e.date,                 designationid=e.designationid                                             }).FirstOrDefault();                                     emp.AvailableDesig = GetDesig();             return PartialView("_AddUpdateData", emp);                     }         [HttpPost]         public ActionResult Delete(int id)         {             db.deleteemployee(id);             db.SaveChanges();             // This comes from database.                    return Json("success", JsonRequestBehavior.AllowGet);         }     } } 

Employee.cs is my model

namespace WebApplication1.Models {     public class Employee     {         public Employee()         {             AvailableDesig = new List<SelectListItem>();         }         public int? empid { get; set; }         [Required(ErrorMessage = "Name Required.")]         public string empname { get; set; }         [Required(ErrorMessage = "Gender Required.")]         public string gender { get; set; }         [Required(ErrorMessage = "Please Select {0}.")]         public Nullable<int> designationid { get; set; }         [Required(ErrorMessage = "Email Address Required.")]         public string empemail { get; set; }         [Required(ErrorMessage = "Salary Required.")]         public Nullable<System.Decimal> empsalary { get; set; }         [Required(ErrorMessage = "Date Required.")]         public Nullable<System.DateTime> date { get; set; }         public int id { get; set; }         public string name { get; set; }         public IList<SelectListItem> AvailableDesig { get; set; }         public IList<Employeedesignation> desig { get; set; }     }     public class Employeedesignation     {         public int id { get; set; }         public string name { get; set; }     } } 

I am also giving you the script to generate the Database

SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[designation](     [id] [int] IDENTITY(1,1) NOT NULL,     [name] [varchar](250) NULL,  CONSTRAINT [PK_designation] PRIMARY KEY CLUSTERED  (     [id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY]  GO SET ANSI_PADDING OFF GO /****** Object:  Table [dbo].[employee]    Script Date: 1/15/2019 10:32:42 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[employee](     [empid] [int] IDENTITY(1,1) NOT NULL,     [empname] [varchar](250) NULL,     [gender] [bit] NULL,     [designationid] [int] NULL,     [empemail] [varchar](250) NULL,     [empsalary] [varchar](250) NULL,     [date] [datetime] NULL,  CONSTRAINT [PK_employee] PRIMARY KEY CLUSTERED  (     [empid] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY]  GO SET ANSI_PADDING OFF GO /****** Object:  StoredProcedure [dbo].[deleteemployee]    Script Date: 1/15/2019 10:32:42 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[deleteemployee]     @empid int AS BEGIN     SET NOCOUNT ON;     delete from employee where empid=@empid END  GO /****** Object:  StoredProcedure [dbo].[insertemployeedata]    Script Date: 1/15/2019 10:32:42 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[insertemployeedata]     @empname varchar(250)=null,     @gender bit,     @designationid int=null,     @empemail varchar(250)=null,     @empsalary decimal(8,2)=null,     @date datetime as BEGIN     SET NOCOUNT ON;     insert into employee values(@empname,@gender,@designationid,@empemail,@empsalary,@date)  END  GO /****** Object:  StoredProcedure [dbo].[selectemployeedata]    Script Date: 1/15/2019 10:32:42 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO  CREATE PROCEDURE [dbo].[selectemployeedata] @empid int=0 AS BEGIN     SET NOCOUNT ON;     if(@empid=0)     begin     select * from employee e inner join designation d on e.designationid=d.id      end     else if (@empid>0)     begin     select * from employee e inner join designation d on e.designationid=d.id where e.empid=@empid      end END  GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO  CREATE PROCEDURE [dbo].[selectemployeeedesignation]  AS BEGIN        SET NOCOUNT ON; select * from designation END  GO  SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[updateemployeedata] @empid int,         @empname varchar(250)=null,     @gender bit,     @designationid int=null,     @empemail varchar(250)=null,     @empsalary decimal(8,2)=null,     @date datetime AS BEGIN     SET NOCOUNT ON;     update employee set empname=@empname, gender=@gender, designationid=@designationid,empemail=@empemail,empsalary=@empsalary,[date]=@date where empid=@empid END  GO 

In my Case the Insertion and updation is taking time Can any one help me to optimize my code

Delete a value from cookie with php

I am storing product id-s in a cookie with php. (These are the favorite products on a webshop.)

I added many products as favorit, so my cookie looks like: 12,55,120,43

What i know, that the $ _COOKIE[$ cookie_name] is not an array. (checked with is_array function)

How can i delete a product id from that cookie? I send the id that i want to delete with ajax to this php file:

    if(isset($  _POST['id'])) {     $  id = intval($  _POST['id']);      $  cookie_name = "kedvenc_termek";     if(isset($  _COOKIE[$  cookie_name]))     {         echo $  _COOKIE[$  cookie_name];     }  } 

Compare two datatables and delete duplicates (without join) C#

I need to compare two datatables, to delete the duplicates and then to fill a gridview.

This is what I have try so far

DataTable cols = new DataTable(); DataTable cols2 = new DataTable(); DataTable cols3 = cols.Copy();   foreach (DataRow row1 in cols2.Rows)             {                 bool isRecordExist = false;                 foreach (DataRow row2 in cols.Rows)            {      if (row1 == row2)             {                 isRecordExist = true;             }          if (!isRecordExist)         {             cols3.ImportRow(row1);         }     }   }    dgvfcolumns.DataSource = cols3; 

but instead of removing the duplicate it just adds the rows from 2nd datatable (cols2) to the the 1st(cols).

any idea? I also like to ask if I have to convert my datatables to arrays? thank you

How to mass delete folders from Windows with paths from a text file [on hold]

I have text file from a game that has a list of duplicate items for said game. I was wondering if there was any way to delete them in one way rather than going through individual paths and deleting them all individually. This is an example line that is provided to me in the text file

E:/Songs/Whyks – Ode to Friendlydad (E:/Songs/Acai’s Setlist/non guitar stuff/whyks-odetofriendlydad)

There are over 7000 lines with different paths so I need to find a way to delete the folder in each path.