gpt4 book ai didi

c# - .Net Core 2.2 中是否有 SaveFileDialog?

转载 作者:太空宇宙 更新时间:2023-11-03 14:38:52 26 4
gpt4 key购买 nike

我正在开发一个具有下载一些记录并将其保存为文本文件的功能的应用程序。如果我为生成的文件放置一个静态位置,它就会工作。我想让用户决定他们想要保存这个文件的位置。 Asp.Net Core 2.2 MVC 中有 SaveFileDialog 吗?

我在 Controller 中的下载操作如下:

 public async Task<IActionResult> DownloadList([Bind("Id,isDownload")] BdoPE bdoPE)
{
UserDetails();
string cncuser = ViewBag.DisplayName;
var config = new CsvHelper.Configuration.Configuration();
config.Delimiter = "\t";

var records = new List<BdoRpt>();

var record = _context.bdoPEs.Where(
c => c.DocType != null &&
c.isDownloaded == false &&
c.CompanyCode != null &&
c.AssignNum != null &&
c.ItemText != null &&
c.ItemText2 != null &&
c.isDownloaded == false &&
c.MarketerZ2 == cncuser).ToList();

if (record.Count > 0)
{
foreach (var data in record)
{
records.Add(new BdoRpt()
{
DocDateInDoc = data.DocDateInDoc,
DocType = data.DocType,
CompanyCode = data.CompanyCode,
PosDateInDoc = data.PosDateInDoc,
FiscalPeriod = data.FiscalPeriod,
CurrentKey = data.CurrentKey,
RefDocNum = data.RefDocNum,
DocHeadT = data.DocHeadT,
PosKeyInNextLine = data.PosKeyInNextLine,
AccMatNextLine = data.AccMatNextLine,
AmountDocCur = data.AmountDocCur,
ValDate = data.ValDate,
AssignNum = data.AssignNum,
ItemText = data.ItemText,
PosKeyInNextLine2 = data.PosKeyInNextLine2,
AccMatNextLine2 = data.AccMatNextLine2,
AmountDocCur2 = data.AmountDocCur2,
BaseDateDueCal = data.BaseDateDueCal,
ItemText2 = data.ItemText2,
});
}

using (var writer = new StreamWriter("C:\\file.txt")) // this is the static location
using (var csv = new CsvWriter(writer, config))
{
csv.WriteRecords(records);
}
recordDownloaded();
var bdope = _context.bdoPEs.Where(
c => c.DocType != null &&
c.isDownloaded == false &&
c.CompanyCode != null &&
c.AssignNum != null &&
c.ItemText != null &&
c.ItemText2 != null &&
c.isDownloaded == false).ToList();

foreach (var data in bdope)
{
data.isDownloaded = true;
}
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Lsmw));
}
else
{
NoRecordFound();
return RedirectToAction(nameof(Lsmw));
}
}

目前在我的代码中,它只是我驱动器 C:\上的文本文件

最佳答案

您可以改为显示下载文件对话框:
https://stackoverflow.com/a/50334901/5137920
请注意不要直接使用任何与桌面开发相关的库,以避免任何兼容性问题。

关于c# - .Net Core 2.2 中是否有 SaveFileDialog?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58518100/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com