Windows explorer program

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?SmFwZQ==?=

    Windows explorer program

    im writing a c# console application that copies files chosen from the windows
    explorer. I chose the files i want to copy and then from the (right key) menu
    chose my program.
    the program starts fine but passes an error that the file(s) are in use ny
    another user. This other user must be the windows explorer. Any workarounds
    to free the files from the windows explorer?
  • =?Utf-8?B?anAybXNmdA==?=

    #2
    RE: Windows explorer program

    Are you trying to copy files from Windows Explorer? I take it you have
    created your own menu item to the Context Menu that Windows Explorer uses.
    I'd be interested to learn how you did that!

    Anyway, on to your problem: Are you creating a copy of the file before you
    try to do anything else with it? What part of your program passes the error?
    Is it the actual copy method? Are you using System.IO.File or something else?
    Have you tried cloning the file?

    You might need to show some code for us to help you better.

    "Jape" wrote:
    im writing a c# console application that copies files chosen from the windows
    explorer. I chose the files i want to copy and then from the (right key) menu
    chose my program.
    the program starts fine but passes an error that the file(s) are in use ny
    another user. This other user must be the windows explorer. Any workarounds
    to free the files from the windows explorer?

    Comment

    • =?Utf-8?B?SmFwZQ==?=

      #3
      RE: Windows explorer program

      I have added my application to the context menu of windows explorer.
      I wrote a short windows program which inserted the menuitem into the
      register (guess you could edit the register manually)
      Then i right-click on the files i want to copy and choose my program from
      the context menu.
      I tried IO.File and IO.FileInfo but both give the same error message that
      the file is in use by another process.
      I also have a Windows version of the application in which i can use two
      different ways of getting the files onto a ListBox from which i submit the
      copy for each file: first by the OpenFileDialog and secondly by dragdrop the
      files from windows explorer. The first way works fine but the second way
      gives the same error as the console application. Even if i clse windows
      explorer before the submitting the copy, the error is the same.

      The copy code i simply:

      FileInfo fi = new FileInfo(filein );
      fi.CopyTo(fileo ut, true);

      or with File it was:

      File.Copy(filei n, fileout, true);




      "jp2msft" wrote:
      Are you trying to copy files from Windows Explorer? I take it you have
      created your own menu item to the Context Menu that Windows Explorer uses.
      I'd be interested to learn how you did that!
      >
      Anyway, on to your problem: Are you creating a copy of the file before you
      try to do anything else with it? What part of your program passes the error?
      Is it the actual copy method? Are you using System.IO.File or something else?
      Have you tried cloning the file?
      >
      You might need to show some code for us to help you better.
      >
      "Jape" wrote:
      >
      im writing a c# console application that copies files chosen from the windows
      explorer. I chose the files i want to copy and then from the (right key) menu
      chose my program.
      the program starts fine but passes an error that the file(s) are in use ny
      another user. This other user must be the windows explorer. Any workarounds
      to free the files from the windows explorer?

      Comment

      • =?Utf-8?B?anAybXNmdA==?=

        #4
        RE: Windows explorer program

        Jape,

        I know this sounds silly, but your filein and fileout *do* have separate
        paths, don't they?

        Otherwise, I don't know what to suggest.

        Have you included your code in a try...catch to see what the exact error
        message is? I'm guessing that error would be "the file(s) are in use by
        another user" or something to that effect.

        You could use the code below to find out exactly what type of error you are
        getting. This should help you narrow it down.

        try {
        File.Copy(filei n, @"C:\Temp\" + filein, true);
        } catch (System.IO.Dire ctoryNotFoundEx ception err) {
        MessageBox.Show (err.Message);
        } catch (System.Argumen tException err) {
        MessageBox.Show (err.Message);
        } catch (System.Unautho rizedAccessExce ption err) {
        MessageBox.Show (err.Message);
        } catch (System.NotSupp ortedException err) {
        MessageBox.Show (err.Message);
        } catch (System.IO.IOEx ception err) {
        MessageBox.Show (err.Message);
        } catch (System.IO.Path TooLongExceptio n err) {
        MessageBox.Show (err.Message);
        } catch (System.Argumen tNullException err) {
        MessageBox.Show (err.Message);
        } catch (System.IO.File NotFoundExcepti on err) {
        MessageBox.Show (err.Message);
        }


        "Jape" wrote:
        I have added my application to the context menu of windows explorer.
        I wrote a short windows program which inserted the menuitem into the
        register (guess you could edit the register manually)
        Then i right-click on the files i want to copy and choose my program from
        the context menu.
        I tried IO.File and IO.FileInfo but both give the same error message that
        the file is in use by another process.
        I also have a Windows version of the application in which i can use two
        different ways of getting the files onto a ListBox from which i submit the
        copy for each file: first by the OpenFileDialog and secondly by dragdrop the
        files from windows explorer. The first way works fine but the second way
        gives the same error as the console application. Even if i clse windows
        explorer before the submitting the copy, the error is the same.
        >
        The copy code i simply:
        >
        FileInfo fi = new FileInfo(filein );
        fi.CopyTo(fileo ut, true);
        >
        or with File it was:
        >
        File.Copy(filei n, fileout, true);
        >
        >
        >
        >
        "jp2msft" wrote:
        >
        Are you trying to copy files from Windows Explorer? I take it you have
        created your own menu item to the Context Menu that Windows Explorer uses.
        I'd be interested to learn how you did that!

        Anyway, on to your problem: Are you creating a copy of the file before you
        try to do anything else with it? What part of your program passes the error?
        Is it the actual copy method? Are you using System.IO.File or something else?
        Have you tried cloning the file?

        You might need to show some code for us to help you better.

        "Jape" wrote:
        im writing a c# console application that copies files chosen from the windows
        explorer. I chose the files i want to copy and then from the (right key) menu
        chose my program.
        the program starts fine but passes an error that the file(s) are in use ny
        another user. This other user must be the windows explorer. Any workarounds
        to free the files from the windows explorer?

        Comment

        • Mike Blake-Knox

          #5
          Re: Windows explorer program

          In article <8085DD97-FCF0-4B16-96DD-8FB8AE8C139C@mi crosoft.com>, Jape wrote:
          Then i right-click on the files i want to copy and choose my program from 
          the context menu. 
          I tried IO.File and IO.FileInfo but both give the same error message that 
          the file is in use by another process.
          I also have a Windows version of the application in which i can use two 
          different ways of getting the files onto a ListBox from which i submit the 
          copy for each file: first by the OpenFileDialog and secondly by dragdrop the 
          files from windows explorer.
          I'm not sure what FileShare mode FileInfo and CopyTo use by default. If the
          explorer keeps the (selected) file open, you will be denied access unless a
          FileShare mode that allows the file to already be open by another process is
          used. You may need to open (FileInfo.Open) the input file with a FileShare
          including Read access.

          Mike

          Comment

          • =?Utf-8?B?SmFwZQ==?=

            #6
            Re: Windows explorer program


            I found out a new "feature" in the problem. The means of the application is
            to copy files form a development server to seversl production servers. Our
            main development server is a w2000 based server. We also have another
            development-server which is a w2003 server.
            From the w2003 server the copying works fine so it seems that the problem
            exists only on the w2000 server. Unfotunately its our main dev-server and
            wont be upgraded for some time to w2003 or w2008.
            Oh, and the error message is: System.IO.IOExc eption: The process cannot
            access the file '\\SERVERX\jtes t1\testi4.asp' because it is being used by
            another process.

            And this SERVERX is the w2000 server.

            "Mike Blake-Knox" wrote:
            In article <8085DD97-FCF0-4B16-96DD-8FB8AE8C139C@mi crosoft.com>, Jape wrote:
            Then i right-click on the files i want to copy and choose my program from
            the context menu.
            I tried IO.File and IO.FileInfo but both give the same error message that
            the file is in use by another process.
            I also have a Windows version of the application in which i can use two
            different ways of getting the files onto a ListBox from which i submit the
            copy for each file: first by the OpenFileDialog and secondly by dragdrop the
            files from windows explorer.
            >
            I'm not sure what FileShare mode FileInfo and CopyTo use by default. If the
            explorer keeps the (selected) file open, you will be denied access unless a
            FileShare mode that allows the file to already be open by another process is
            used. You may need to open (FileInfo.Open) the input file with a FileShare
            including Read access.
            >
            Mike
            >
            >

            Comment

            Working...