Accessing files over network

can somebody assist me how to access the files over the network in a web application using C#. I need to copy a certain file from server to local machine in a web application using C#, can somebody help me regarding this.

thank you



Answer this question

Accessing files over network

  • entrance80

    thanks for the reply........what is given is ok but i want the namespace to access over the network. I tried what u specified but it is giving URI error. can u please send in detail .........

    thanks


  • Erik11

    Hi, I got it working already, but have one question on it.

    What if the remote folder needs authentication How is it supposed to be done

    Can give us some example code of copying to a remote folder, if it's PC's shared
    folder needs to be authenticated first

    Thanks in advance!!!

    Paul.


  • Thomas S. Andersen

    The System.IO.File class can be used to copy files using UNC as the pathname. So, assuming appropriate permissions, you should be able to do something like.

    System.IO.File.Copy(fromPath, toPath);

    where fromPath (and or toPath) is in the form of "\\MyServer\MyShare\filename"

    Hope that helps.



  • thedazman

    In C# the backslash character signals an escape sequence, so specifying file paths the same way as you do in (for example) Windows Explorer leads to errors. Try doubling each backslash in your path, OR put a '@' character in front of the path string (e.g. @\\myServer\mypath\myfile.txt).

  • Accessing files over network