English 中文(简体)
putting a stream in the clipboard
原标题:

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?

最佳回答

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.

问题回答

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

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());
    }
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签