File copy with progress

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Johnny Jörgensen

    #1

    File copy with progress

    Using File.Copy in the System.IO namespace, it's easy to copy one or more
    files.

    But I wonder: Is it possible to get windows to display its File Copy
    Progress dialog at the same time - or alternatively get callbacks with the
    progress?

    Same goes for deleting files...

    Cheers,
    Johnny J.


  • Alberto Poblacion

    #2
    Re: File copy with progress

    "Johnny Jörgensen" <jojo@altcom.se wrote in message
    news:OYXCj%236K JHA.1012@TK2MSF TNGP04.phx.gbl. ..
    Using File.Copy in the System.IO namespace, it's easy to copy one or more
    files.
    >
    But I wonder: Is it possible to get windows to display its File Copy
    Progress dialog at the same time - or alternatively get callbacks with the
    progress?
    >
    Same goes for deleting files...
    This can be achieved by means of a call to the Shell function
    ShFileOperation . You can do this from your .Net program by means of Platform
    Invoke. The declaration, along with some sample code, can be found at
    pinvoke.net:


    Comment

    • Johnny Jörgensen

      #3
      Re: File copy with progress

      Thanks a lot, Alberto, I'll look into that.

      /Johnny J.




      "Alberto Poblacion" <earthling-quitaestoparaco ntestar@poblaci on.orgskrev i
      meddelandet news:OxZCxO7KJH A.4708@TK2MSFTN GP02.phx.gbl...
      "Johnny Jörgensen" <jojo@altcom.se wrote in message
      news:OYXCj%236K JHA.1012@TK2MSF TNGP04.phx.gbl. ..
      >Using File.Copy in the System.IO namespace, it's easy to copy one or more
      >files.
      >>
      >But I wonder: Is it possible to get windows to display its File Copy
      >Progress dialog at the same time - or alternatively get callbacks with
      >the progress?
      >>
      >Same goes for deleting files...
      >
      This can be achieved by means of a call to the Shell function
      ShFileOperation . You can do this from your .Net program by means of
      Platform Invoke. The declaration, along with some sample code, can be
      found at pinvoke.net:

      >

      Comment

      • kimiraikkonen

        #4
        Re: File copy with progress

        On Oct 11, 5:42 pm, "Johnny Jörgensen" <j...@altcom.se wrote:
        Using File.Copy in the System.IO namespace, it's easy to copy one or more
        files.
        >
        But I wonder: Is it possible to get windows to display its File Copy
        Progress dialog at the same time - or alternatively get callbacks with the
        progress?
        >
        Same goes for deleting files...
        >
        Cheers,
        Johnny J.
        Yes, using P/Invoke with SHFileOperation API is the long and risky way
        to write the whole code error-free, that's why My namespace in VB.NET
        provides a well-wrapper for this:

        My.Computer.Fil eSystem.CopyFil e("source","des t", _
        True,FileIO.UIC ancelOption.DoN othing)

        The third parameter, which is "showUI", lets you to view native dialog
        while copying is in progress.

        http://msdn.microsoft.com/en-us/libr...yf(VS.80).aspx

        Though yours is cross-post, you can call the same function in C# by
        referencing it to Microsoft.Visua lBasic.dll from .NET tab in "Add
        Reference" menu with the following code:

        using Microsoft.Visua lBasic.Devices;

        Computer copyfile = new Computer();
        //Pass parameters below including showUI
        copyfile.FileSy stem.CopyFile(. ..);

        Hope this helps,

        Onur Güzel

        Comment

        • Gillard

          #5
          Re: File copy with progress

          My.Computer.Fil eSystem.CopyFil e("source", "destinatio n",
          Microsoft.Visua lBasic.FileIO.U IOption.AllDial ogs,
          FileIO.UICancel Option.DoNothin g)


          "Johnny Jörgensen" <jojo@altcom.se wrote in message
          news:uUyYqV7KJH A.5740@TK2MSFTN GP06.phx.gbl...
          Thanks a lot, Alberto, I'll look into that.
          >
          /Johnny J.
          >
          >
          >
          >
          "Alberto Poblacion" <earthling-quitaestoparaco ntestar@poblaci on.orgskrev
          i meddelandet news:OxZCxO7KJH A.4708@TK2MSFTN GP02.phx.gbl...
          >"Johnny Jörgensen" <jojo@altcom.se wrote in message
          >news:OYXCj%236 KJHA.1012@TK2MS FTNGP04.phx.gbl ...
          >>Using File.Copy in the System.IO namespace, it's easy to copy one or
          >>more files.
          >>>
          >>But I wonder: Is it possible to get windows to display its File Copy
          >>Progress dialog at the same time - or alternatively get callbacks with
          >>the progress?
          >>>
          >>Same goes for deleting files...
          >>
          > This can be achieved by means of a call to the Shell function
          >ShFileOperatio n. You can do this from your .Net program by means of
          >Platform Invoke. The declaration, along with some sample code, can be
          >found at pinvoke.net:
          > http://www.pinvoke.net/default.aspx/...Operation.html
          >>
          >
          >

          Comment

          • kimiraikkonen

            #6
            Re: File copy with progress

            On Oct 11, 6:31 pm, kimiraikkonen <kimiraikkone.. .@gmail.comwrot e:
            On Oct 11, 5:42 pm, "Johnny Jörgensen" <j...@altcom.se wrote:
            >
            Using File.Copy in the System.IO namespace, it's easy to copy one or more
            files.
            >
            But I wonder: Is it possible to get windows to display its File Copy
            Progress dialog at the same time - or alternatively get callbacks with the
            progress?
            >
            Same goes for deleting files...
            >
            Cheers,
            Johnny J.
            >
            Yes, using P/Invoke with SHFileOperation API is the long and risky way
            to write the whole code error-free, that's why My namespace in VB.NET
            provides a well-wrapper for this:
            >
            My.Computer.Fil eSystem.CopyFil e("source","des t", _
            True,FileIO.UIC ancelOption.DoN othing)
            >
            Minor correction related to code above from myself, use that instead:

            My.Computer.Fil eSystem.CopyFil e _
            ("C:\source.txt ", _
            "C:\folder\dest .txt",
            Microsoft.Visua lBasic.FileIO.U IOption.AllDial ogs, _
            FileIO.UICancel Option.DoNothin g)

            HTH,

            Onur Güzel




            Comment

            • Herfried K. Wagner [MVP]

              #7
              Re: File copy with progress

              "Johnny Jörgensen" <jojo@altcom.se schrieb:
              Using File.Copy in the System.IO namespace, it's easy to copy one or more
              files.
              >
              But I wonder: Is it possible to get windows to display its File Copy
              Progress dialog at the same time - or alternatively get callbacks with the
              progress?
              In addition to the other replies:

              Wrapper around 'CopyFileEx' using the progress callback (suitable for
              copying single files):

              <URL:http://dotnet.mvps.org/dotnet/samples/filesystem/Transactions.zi p>

              --
              M S Herfried K. Wagner
              M V P <URL:http://dotnet.mvps.org/>
              V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

              Comment

              Working...