Can I use IFileOperation to copy a virtual file to the local disk?

Sam Barraclough 85 Reputation points
2023-02-14T20:40:32.7133333+00:00

I'm trying to copy files from a network stream to the local disk (with C#). I want to use the IFileOperation interface to get the modern copy UI, however I'm not sure how to get a IShellItem for a file that does not yet exist.

Currently I'm using the older IOperationsProgressDialog; which does work however I'm wanting the shell to deal with asking the user to overwite files, permssion issues ect.

My question is: how do I create an IShellItem from an IStream (or something similar) to use in IFileOperation:Copy?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,749 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,344 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Xiaopo Yang - MSFT 12,726 Reputation points Microsoft External Staff
    2023-02-15T02:10:30.5733333+00:00

    Hello,

    Welcome to Microsoft Q&A!

    As ShellStorage shows, you can IShellItem::BindToHandler(,BHID_Stream,); to cooperate with IStream.

            IStream *pstream;
            hr = psi->BindToHandler(pbc, BHID_Stream, IID_PPV_ARGS(&pstream));
    

    Thank you.

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.