将流放入剪贴板

发布于 2024-08-14 05:38:11 字数 270 浏览 2 评论 0原文

让我们从最终目标开始 -
我需要能够将从 Web 响应流获取的文件粘贴到本地文件系统中。

我认为最好的做法是以某种方式将一些内容放入剪贴板中,以便在发生粘贴操作时通知我,这样我就可以运行异步请求,等待响应,并将流发送到文件系统。是否有可能做这样的事情?
如果没有,也许我可以在复制操作上发送请求,获取流(甚至可能将其完全复制到 MemoryStream 中,这样我就可以关闭响应),并以某种方式将其放入剪贴板中,这样粘贴只会“溢出”所有内容吗?

这里有人对我有什么建议或指示吗?

Lets begin with the final goal -
I need to able to paste a file into the local file system, that is obtained from a web response stream.

I think that the best course of action is to somehow put something inside the clipboard that will notify me when the pasting action occurs, so I can then run the async request, wait for the response, and send in the stream to the file system. Is it at all possible to do something like that?
If not, maybe I can send the request on the copy operation, obtain the stream (perhaps even copying it fully into a MemoryStream, so I can close the response), and somehow put it inside the clipboard so that pasting will just "spill" it all out?

Anyone here has any suggestions or pointers for me?

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

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

发布评论

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

评论(3

无敌元气妹 2024-08-21 05:38:11

也许您可以将文件保存到 Temp 文件夹 (Path.GetTempPath()),然后使用常规 Windows 复制/粘贴机制 (Clipboard.SetFileDropList)

Maybe you can save the file to the Temp folder (Path.GetTempPath()), and then use the regular windows copy/paste mechanism (Clipboard.SetFileDropList)

同尘 2024-08-21 05:38:11

我发现这个问题,带有链接CodeProject 的一篇文章解释了我应该做什么。目前正在尝试自己解决这个问题。

I have found this question, with links to a CodeProject article explaining what I should do. Trying to figure it out myself at the moment.

零度° 2024-08-21 05:38:11

此示例将网格的内容保存到临时文件并将所有行加载到剪贴板中,以便可以将它们粘贴到 Excel 中:

String filename = Path.Combine(Path.GetTempPath(), "grid.csv");
using (Stream stream = new MemoryStream())
{
    this.Grid.Export(stream,new GridViewExportOptions() {Format = ExportFormat.Csv, ShowColumnHeaders = true});
    stream.Position = 0;
    using (StreamReader r = new StreamReader(stream))
    {
        Clipboard.SetData(DataFormats.CommaSeparatedValue, r.ReadToEnd());
    }
}

This example saves the contents of a grid to a temporary file and loads all the rows into the clipboard so they can be pasted into Excel:

String filename = Path.Combine(Path.GetTempPath(), "grid.csv");
using (Stream stream = new MemoryStream())
{
    this.Grid.Export(stream,new GridViewExportOptions() {Format = ExportFormat.Csv, ShowColumnHeaders = true});
    stream.Position = 0;
    using (StreamReader r = new StreamReader(stream))
    {
        Clipboard.SetData(DataFormats.CommaSeparatedValue, r.ReadToEnd());
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文