File.Copy

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

    File.Copy

    Hi I would like to use File.Copy with UNC paths. I have seen this problem
    reported by others as well. Can i use File.Copy with UNC paths. ie., i would
    like to copy a file from one of the folder to a shared folder. eg.,

    File.Copy(srcPa th, "\\machinename\ \folder)

    This is giving an error "Could not find part of the path
    \\machinename\\ folder"

    Is this feature supported? if yes please can anyone let me knwo how to
    achieve it.

    Thanks
  • Mythran

    #2
    Re: File.Copy



    "Ganesha" <Ganesha@discus sions.microsoft .comwrote in message
    news:8370CEFE-79D6-465D-A4FB-841BB82649F8@mi crosoft.com...
    Hi I would like to use File.Copy with UNC paths. I have seen this problem
    reported by others as well. Can i use File.Copy with UNC paths. ie., i
    would
    like to copy a file from one of the folder to a shared folder. eg.,
    >
    File.Copy(srcPa th, "\\machinename\ \folder)
    >
    This is giving an error "Could not find part of the path
    \\machinename\\ folder"
    >
    Is this feature supported? if yes please can anyone let me knwo how to
    achieve it.
    >
    Thanks
    Try escaping a double-backslash before machinename:

    File.Copy(srcPa th, "\\\\machinenam e\\folder");

    - OR -

    File.Copy(srcPa th, @"\\machinename \folder");

    I haven't tested to ensure that File.Copy can copy to a network folder via a
    UNC path, so this may not be your solution, but as it stands by looking,
    that could be the problem.

    HTH,
    Mythran


    Comment

    • Leon Jollans

      #3
      Re: File.Copy

      Hi Ganesha.
      The problem is probably that you need to provide credentials to the current
      thread before you can access the share.
      if you run the program as a user who has access to the server share it
      should work

      in fact, if the current user has logged on with remote credentials
      succesfully this session it should also work.

      but if that's not an option you may need to drop into p/invoke to get
      windows to manage the logon context for you.. and that's something I'd have
      to look up myself.

      Leon

      "Mythran" <Mythran@commun ity.nospamwrote in message
      news:33385932-A29B-4016-A831-94D14DA690ED@mi crosoft.com...
      >
      >
      "Ganesha" <Ganesha@discus sions.microsoft .comwrote in message
      news:8370CEFE-79D6-465D-A4FB-841BB82649F8@mi crosoft.com...
      >Hi I would like to use File.Copy with UNC paths. I have seen this problem
      >reported by others as well. Can i use File.Copy with UNC paths. ie., i
      >would
      >like to copy a file from one of the folder to a shared folder. eg.,
      >>
      >File.Copy(srcP ath, "\\machinename\ \folder)
      >>
      >This is giving an error "Could not find part of the path
      >\\machinename\ \folder"
      >>
      >Is this feature supported? if yes please can anyone let me knwo how to
      >achieve it.
      >>
      >Thanks
      >
      Try escaping a double-backslash before machinename:
      >
      File.Copy(srcPa th, "\\\\machinenam e\\folder");
      >
      - OR -
      >
      File.Copy(srcPa th, @"\\machinename \folder");
      >
      I haven't tested to ensure that File.Copy can copy to a network folder via
      a UNC path, so this may not be your solution, but as it stands by looking,
      that could be the problem.
      >
      HTH,
      Mythran
      >
      >

      Comment

      • =?Utf-8?B?Q2lhcmFuIE8nJ0Rvbm5lbGw=?=

        #4
        Re: File.Copy

        I have an impersonation class on my blog which you call a function passing
        the impersonation info (doman, username, password) and it raises an event in
        which you can do the work while impersonated. When the event handler
        completes, it undoes the impersonation. Its a handy tool to stop you having
        to look that stuff up and do the Dll imports every time.
        Let me know what you think.

        --
        Ciaran O''Donnell
        try{ Life(); } catch (TooDifficultException) { throw Toys(); }



        "Leon Jollans" wrote:
        Hi Ganesha.
        The problem is probably that you need to provide credentials to the current
        thread before you can access the share.
        if you run the program as a user who has access to the server share it
        should work
        >
        in fact, if the current user has logged on with remote credentials
        succesfully this session it should also work.
        >
        but if that's not an option you may need to drop into p/invoke to get
        windows to manage the logon context for you.. and that's something I'd have
        to look up myself.
        >
        Leon
        >
        "Mythran" <Mythran@commun ity.nospamwrote in message
        news:33385932-A29B-4016-A831-94D14DA690ED@mi crosoft.com...


        "Ganesha" <Ganesha@discus sions.microsoft .comwrote in message
        news:8370CEFE-79D6-465D-A4FB-841BB82649F8@mi crosoft.com...
        Hi I would like to use File.Copy with UNC paths. I have seen this problem
        reported by others as well. Can i use File.Copy with UNC paths. ie., i
        would
        like to copy a file from one of the folder to a shared folder. eg.,
        >
        File.Copy(srcPa th, "\\machinename\ \folder)
        >
        This is giving an error "Could not find part of the path
        \\machinename\\ folder"
        >
        Is this feature supported? if yes please can anyone let me knwo how to
        achieve it.
        >
        Thanks
        Try escaping a double-backslash before machinename:

        File.Copy(srcPa th, "\\\\machinenam e\\folder");

        - OR -

        File.Copy(srcPa th, @"\\machinename \folder");

        I haven't tested to ensure that File.Copy can copy to a network folder via
        a UNC path, so this may not be your solution, but as it stands by looking,
        that could be the problem.

        HTH,
        Mythran
        >

        Comment

        Working...