<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Creating something from nothing, asynchronously [Developer-friendly virtual file implementation for .NET improved!]</title><link>http://blogs.msdn.com/b/delay/archive/2009/11/04/creating-something-from-nothing-asynchronously-developer-friendly-virtual-file-implementation-for-net-improved.aspx</link><description>Last week I posted the code for VirtualFileDataObject, an easy-to-use implementation of virtual files for .NET and WPF . This code implements the standard IDataObject COM interface for drag-and-drop and clipboard operations and is specifically targeted</description><dc:language>en</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Creating something from nothing, asynchronously [Developer-friendly virtual file implementation for .NET improved!]</title><link>http://blogs.msdn.com/b/delay/archive/2009/11/04/creating-something-from-nothing-asynchronously-developer-friendly-virtual-file-implementation-for-net-improved.aspx#10421214</link><pubDate>Fri, 24 May 2013 17:15:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10421214</guid><dc:creator>David Anson</dc:creator><description>&lt;p&gt;Joe,&lt;/p&gt;
&lt;p&gt;Got it, thanks for clarifying! Unfortunately, you&amp;#39;re working right at the boundary of my memory/experience, so I don&amp;#39;t know the right answer. :( That said, I think you&amp;#39;re on the right track - what I&amp;#39;d suggest is to look at the SetData method that calls CreateStreamOnHGlobal and see if there are other options (ex: dwAspect or tymed) that would allow you to do what you want (i.e., provide something other than an in-memory stream). Also, I think there&amp;#39;s a deferred-render mode for clipboard data that might be relevant/useful here because it waits to provide the data until it&amp;#39;s needed and the file name should be available at that time.&lt;/p&gt;
&lt;p&gt;If you figure this out, please let me know what you ended up doing - I&amp;#39;d love to learn! :)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10421214" width="1" height="1"&gt;</description></item><item><title>re: Creating something from nothing, asynchronously [Developer-friendly virtual file implementation for .NET improved!]</title><link>http://blogs.msdn.com/b/delay/archive/2009/11/04/creating-something-from-nothing-asynchronously-developer-friendly-virtual-file-implementation-for-net-improved.aspx#10421111</link><pubDate>Fri, 24 May 2013 07:50:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10421111</guid><dc:creator>Joe</dc:creator><description>&lt;p&gt;Sorry, chunks of 4096 bytes, not kb :)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10421111" width="1" height="1"&gt;</description></item><item><title>re: Creating something from nothing, asynchronously [Developer-friendly virtual file implementation for .NET improved!]</title><link>http://blogs.msdn.com/b/delay/archive/2009/11/04/creating-something-from-nothing-asynchronously-developer-friendly-virtual-file-implementation-for-net-improved.aspx#10421108</link><pubDate>Fri, 24 May 2013 07:40:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10421108</guid><dc:creator>Joe</dc:creator><description>&lt;p&gt;Yeah, that is exactly what I&amp;#39;m doing. In the FileDescriptor.StreamContents callback, I open a stream to the file on disk, read it in chunks of 4096kb, and write each chunk to the stream provided by the VirtualFileDataObject in the callback. I guess that&amp;#39;s the common way of doing such things. But it seems the problem is the line &amp;nbsp;var iStream = NativeMethods.CreateStreamOnHGlobal(IntPtr.Zero, true); in the GetData function of the DataObject. This writes all chunks to the global memory, not to disc... so every time I write to the stream, I write to global memory and at some point this is full, which leads to a &amp;quot;Not enough storage&amp;quot; message. This even occurs, when I use the stream.copyTo function. I wish I could use SHCreateStreamOnFileEx instead of CreateStreamOnHGlobal, but this requires that I know the location of the file before dropping it to the explorer, but the file itself is created INSIDE the FileDescriptor.StreamContents callback.&lt;/p&gt;
&lt;p&gt;So what I want to do is:&lt;/p&gt;
&lt;p&gt;private void onStream(Stream stream)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // create the file after dropping some items of my application to the explorer to a temporary location&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // waiting until file creation has finished, after this I know where I find the file and how it is named.&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Open a stream to the created file and &amp;quot;move&amp;quot; it to the location where it has been dropped. I do this by copying the bytes from the source stream to the target stream. But this leads to the problem I mentioned, because all is written to &amp;nbsp; global memory. SHCreateStreamOnFileEx seems to work if I knew the filename in advance, but this is created after the stream has been opened.&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10421108" width="1" height="1"&gt;</description></item><item><title>re: Creating something from nothing, asynchronously [Developer-friendly virtual file implementation for .NET improved!]</title><link>http://blogs.msdn.com/b/delay/archive/2009/11/04/creating-something-from-nothing-asynchronously-developer-friendly-virtual-file-implementation-for-net-improved.aspx#10420947</link><pubDate>Thu, 23 May 2013 16:28:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10420947</guid><dc:creator>David Anson</dc:creator><description>&lt;p&gt;Joe,&lt;/p&gt;
&lt;p&gt;It sounds like you&amp;#39;re providing an implementation of FileDescriptor.StreamContents that reads from a file and writes it to a stream. When doing so, you want to read from the file in a series of small chunk and write each chunk to the stream before moving on to the next chunk. For example, create a 1000 byte buffer, read into it from the file, write that out to the stream, read the next 1000 bytes, etc.. In this manner, you&amp;#39;ll only be using 1000 bytes of memory at a time no matter how large the file is.&lt;/p&gt;
&lt;p&gt;This is such a common pattern that recent versions of .NET offer the Stream.CopyTo method (&lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/en-us/library/system.io.stream.copyto.aspx"&gt;msdn.microsoft.com/.../system.io.stream.copyto.aspx&lt;/a&gt;) which handles this for you!&lt;/p&gt;
&lt;p&gt;I hope this helps!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10420947" width="1" height="1"&gt;</description></item><item><title>re: Creating something from nothing, asynchronously [Developer-friendly virtual file implementation for .NET improved!]</title><link>http://blogs.msdn.com/b/delay/archive/2009/11/04/creating-something-from-nothing-asynchronously-developer-friendly-virtual-file-implementation-for-net-improved.aspx#10420884</link><pubDate>Thu, 23 May 2013 12:41:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10420884</guid><dc:creator>Joe</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I have a problem when trying to drag/drop large files using VirtualFileDataObject.&lt;/p&gt;
&lt;p&gt;What I do is to open a filestream to the source file, reading the bytes from the source filestream and writing those bytes to the Stream, &lt;/p&gt;
&lt;p&gt;which was delivered by the callback function of &amp;quot;fileDescriptor.StreamContents&amp;quot;,&lt;/p&gt;
&lt;p&gt;using the &amp;quot;stream.Write&amp;quot; function. But this seems to write all bytes from the source file to memory first, before dumping it all to the harddisc.&lt;/p&gt;
&lt;p&gt;This sometimes leads to an OutOfMemoryException if the file is bigger than several hundered Megabyte.&lt;/p&gt;
&lt;p&gt;Is there any solution to this? I have to admit that I&amp;#39;m not that skilled in COM programming, so I do not know what to change in the VirtualFileDataObject...&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10420884" width="1" height="1"&gt;</description></item><item><title>re: Creating something from nothing, asynchronously [Developer-friendly virtual file implementation for .NET improved!]</title><link>http://blogs.msdn.com/b/delay/archive/2009/11/04/creating-something-from-nothing-asynchronously-developer-friendly-virtual-file-implementation-for-net-improved.aspx#10420831</link><pubDate>Thu, 23 May 2013 08:42:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10420831</guid><dc:creator>Vijay G</dc:creator><description>&lt;p&gt;Thank you David for your valuable comment.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10420831" width="1" height="1"&gt;</description></item><item><title>re: Creating something from nothing, asynchronously [Developer-friendly virtual file implementation for .NET improved!]</title><link>http://blogs.msdn.com/b/delay/archive/2009/11/04/creating-something-from-nothing-asynchronously-developer-friendly-virtual-file-implementation-for-net-improved.aspx#10420651</link><pubDate>Wed, 22 May 2013 16:41:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10420651</guid><dc:creator>David Anson</dc:creator><description>&lt;p&gt;Vijay G,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not sure that&amp;#39;s possible. If the target application doesn&amp;#39;t want to opt-into asynchronous mode, I think that&amp;#39;s its choice and that Windows doesn&amp;#39;t try to shim the operation. As a drag-drop source, you should try to support both modes, but be happy to provide data however the target asks for it. :)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10420651" width="1" height="1"&gt;</description></item><item><title>re: Creating something from nothing, asynchronously [Developer-friendly virtual file implementation for .NET improved!]</title><link>http://blogs.msdn.com/b/delay/archive/2009/11/04/creating-something-from-nothing-asynchronously-developer-friendly-virtual-file-implementation-for-net-improved.aspx#10420527</link><pubDate>Wed, 22 May 2013 08:00:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10420527</guid><dc:creator>Vijay G</dc:creator><description>&lt;p&gt;Hi David,&lt;/p&gt;
&lt;p&gt;Really a great article, thanks a lot!!!&lt;/p&gt;
&lt;p&gt;I am facing one issue, how to force synchronous process to asynchronous? My use case is - I am dragging file to Outlook in that case VirtualFileDataObject doesn&amp;#39;t call the GetAsyncMode() function, like it get called when dragging to explorer. I&amp;#39;ve tried all option to set IsAsynchronous to true, but not succeed. Waiting for your valuable response.&lt;/p&gt;
&lt;p&gt;Thank you.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10420527" width="1" height="1"&gt;</description></item><item><title>re: Creating something from nothing, asynchronously [Developer-friendly virtual file implementation for .NET improved!]</title><link>http://blogs.msdn.com/b/delay/archive/2009/11/04/creating-something-from-nothing-asynchronously-developer-friendly-virtual-file-implementation-for-net-improved.aspx#10414288</link><pubDate>Fri, 26 Apr 2013 16:30:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10414288</guid><dc:creator>David Anson</dc:creator><description>&lt;p&gt;I don&amp;#39;t see that you can - it&amp;#39;s likely to be in a different process about which the drop source knows nothing, so it&amp;#39;s not clear what kind of information could be provided to the source that would be generally useful.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10414288" width="1" height="1"&gt;</description></item><item><title>re: Creating something from nothing, asynchronously [Developer-friendly virtual file implementation for .NET improved!]</title><link>http://blogs.msdn.com/b/delay/archive/2009/11/04/creating-something-from-nothing-asynchronously-developer-friendly-virtual-file-implementation-for-net-improved.aspx#10414193</link><pubDate>Fri, 26 Apr 2013 09:59:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10414193</guid><dc:creator>Kei</dc:creator><description>&lt;p&gt;How can I get Dropping location?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10414193" width="1" height="1"&gt;</description></item></channel></rss>