在用户方面下载文件

发布于 2025-02-10 01:02:05 字数 382 浏览 2 评论 0原文

我正在寻找一种将文件保存到用户文件的方法 目录

我将HTML转换为PDF,然后将PDF保存到临时文件,

    string fileName = System.IO.Path.GetTempPath() + id.ToString() + ".pdf";
    await page.PdfAsync(fileName)

在这里我尝试下载文件(.pdf)在用户网站上,

    var client = new WebClient();
    client.DownloadFile(fileName, $"{id}.pdf"); 

但我认为它保存到服务器 未显示应用程序时用户方面的任何内容都没有显示

I'm looking for a way to save the file to the user's files
directory

I convert html to pdf, and save pdf to temporary file

    string fileName = System.IO.Path.GetTempPath() + id.ToString() + ".pdf";
    await page.PdfAsync(fileName)

Here I try download file (.pdf) on the user's site

    var client = new WebClient();
    client.DownloadFile(fileName, 
quot;{id}.pdf"); 

but I think it save to the server
nothing on the user's side when the app is published is not displayed

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

云胡 2025-02-17 01:02:05

我想您可以从此处使用

https:> https:> https: //www.codeproject.com/articles/878605/getting-all-pecial-folders-in-net

,然后在客户端做出这样的事情

var client = new WebClient();
client.DownloadFile(fileName, Path.Combine(KnownFolders.GetPath(KnownFolder.Downloads), $"{id}.pdf"));

I guess you can use the class KnownFolders from here

https://www.codeproject.com/Articles/878605/Getting-All-Special-Folders-in-NET

and then on the client side make something like that

var client = new WebClient();
client.DownloadFile(fileName, Path.Combine(KnownFolders.GetPath(KnownFolder.Downloads), 
quot;{id}.pdf"));
孤蝉 2025-02-17 01:02:05

如果您要允许使用该应用程序下载文件的人:

您可以使用 https:// github 。

public async Task<Stream> BytesStreamWord(string html)
  { 
    await using var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true });
    await using var page = await browser.NewPageAsync();
    await page.SetContentAsync(html);
    var result = await page.GetContentAsync();

    Stream bytesStream = await page.PdfStreamAsync();

   return bytesStream;
}

    return File(bytesStream, "application/pdf", "sampleName.pdf");

if you want allow the person who will use the application to download the file:

u can use https://github.com/hardkoded/puppeteer-sharp to convert html to .pdf in Stream format

ServiceController

public async Task<Stream> BytesStreamWord(string html)
  { 
    await using var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true });
    await using var page = await browser.NewPageAsync();
    await page.SetContentAsync(html);
    var result = await page.GetContentAsync();

    Stream bytesStream = await page.PdfStreamAsync();

   return bytesStream;
}

and use return File() in method

ExportController

    return File(bytesStream, "application/pdf", "sampleName.pdf");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文