[docker]—格式化docker文字命令輸出
docker ps -a --format "{{.Names}}\t{{.ID}}"

這樣就不會亂跑掉

參數如下

PlaceholderDescription
.IDContainer ID
.ImageImage ID
.CommandQuoted command
.CreatedAtTime when the container was created.
.RunningForElapsed time since the container was started.
.PortsExposed ports.
.StatusContainer status.
.SizeContainer disk size.
.NamesContainer names.
.LabelsAll labels assigned to the container.
.LabelValue of a specific label for this container. For example ‘{{.Label “com.docker.swarm.cpu”}}’
.MountsNames of the volumes mounted in this container.
.NetworksNames of the networks attached to this container.
[.net]—.net 6下載檔案

直接指向檔案路徑會報錯,要用下列方式產生檔案匯流


        [HttpGet]
        public IActionResult Index()
        {

            string fileName = HttpContext.Request.Query["filename"].ToString();
            if (fileName.Equals(""))
            {
                return View();
            } else {

                string _folder = $@"{env.WebRootPath}" + configuration.GetValue<string>("AppSetting:tmp_folder") + fileName;
                var net = new System.Net.WebClient();
                //var data = net.DownloadData(link);
                var data=System.IO.File.ReadAllBytes(_folder);
                var content = new System.IO.MemoryStream(data);
                var contentType = "application/vnd.ms-excel";
                //var fileName = "something.bin";


                System.IO.File.Delete(_folder);  


                return File(content, contentType, fileName);

            }
            

        }

黃色部份為下載完畢就刪除檔案,免得爬蟲亂抓檔案造成困擾

[.net]—.net 6使用npoi產生excel檔案

如下

public bool GenNpoiExcel(DataSet dsData, string strfileName)
        {
            NPOI.HSSF.UserModel.HSSFWorkbook workbook = new NPOI.HSSF.UserModel.HSSFWorkbook();
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            int Ii, Jj, Kk;
            NPOI.HSSF.UserModel.HSSFCell cell;
            NPOI.HSSF.UserModel.HSSFRow Row;



            for (Kk = 0; Kk < dsData.Tables.Count; Kk++)
            {
                // 新增試算表。
                NPOI.HSSF.UserModel.HSSFSheet sheet = (NPOI.HSSF.UserModel.HSSFSheet)workbook.CreateSheet(dsData.Tables[Kk].TableName);
                //插入資料值。
                //Header
                NPOI.HSSF.UserModel.HSSFRow rowItem = (NPOI.HSSF.UserModel.HSSFRow)sheet.CreateRow(0);

                for (Ii = 0; Ii < dsData.Tables[Kk].Rows.Count; Ii++)
                {

                    rowItem = (NPOI.HSSF.UserModel.HSSFRow)sheet.CreateRow(Ii);
                    for (Jj = 0; Jj < dsData.Tables[Kk].Columns.Count; Jj++)
                    {


                        rowItem.CreateCell(Jj).SetCellValue(dsData.Tables[Kk].Rows[Ii][Jj].ToString().Trim().Replace("\n", "\r\n").Replace("&nbsp;", "").Trim());
                      

                    }
                }



            }
            workbook.Write(ms);

            string _folder = $@"{env.WebRootPath}" + configuration.GetValue<string>("AppSetting:tmp_folder");


            if (!System.IO.Directory.Exists(_folder))
            {
                System.IO.Directory.CreateDirectory(_folder);
            }
            System.IO.File.WriteAllBytes(_folder + strfileName, ms.ToArray());
            
          

            workbook = null;
            ms.Close();
            ms.Dispose();
            return true;
        }

要使用 env.WebRootPath 這個方法,要在建構子宣告

  IConfiguration configuration;
        Microsoft.AspNetCore.Hosting.IWebHostEnvironment env;

        
        public RegALLComputerController(IConfiguration iConfig, Microsoft.AspNetCore.Hosting.IWebHostEnvironment ienv)
        {
            configuration = iConfig;
            env = ienv;
           
        }
[.net]—.net 6 使用非預設View路徑

放在Progrma.cs裡面

builder.Services.AddControllers();

builder.Services.AddRazorPages().AddRazorRuntimeCompilation();
builder.Services.Configure<Microsoft.AspNetCore.Mvc.Razor.RazorViewEngineOptions>(o =>
{
    o.ViewLocationFormats.Clear();
    //o.ViewLocationFormats.Add("/Views/{0}" + Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.ViewExtension);
    o.ViewLocationFormats.Add("/Views/{1}/{0}" + Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.ViewExtension);
    o.ViewLocationFormats.Add("/Views/{1}/{0}/" + Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.ViewExtension);
    o.ViewLocationFormats.Add("/Views/Shared/{0}" + Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.ViewExtension);
});

就這樣,改變原本吃Pages的設定

[docker]清除佔用空間
$ docker system prune --help

Usage:  docker system prune [OPTIONS]

Remove unused data

Options:
  -a, --all             Remove all unused images not just dangling ones
      --filter filter   Provide filter values (e.g. 'label=<key>=<value>')
  -f, --force           Do not prompt for confirmation
      --volumes         Prune volumes