Create a text file on a network path using C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vickyvick
    New Member
    • Jul 2008
    • 4

    Create a text file on a network path using C#

    Hi,

    I'm new to C# and I'm developeing a utility which creates a text file and populates it with registry key values.

    It works fine on a local path, but with absolute path, it throws an error that "Access to the path .... is deined". Code is given below.

    StreamWriter SW1;
    FileIOPermissio n myPerm = new FileIOPermissio n(FileIOPermiss ionAccess.Write , "\\\\192.168.48 .125\\Shared");
    myPerm.Assert() ;
    //new FileIOPermissio n(FileIOPermiss ionAccess.Write , finfo.Directory .FullName).Dema nd();
    SW1 = File.CreateText ("\\\\192.168.4 8.125\\Shared") ;

    I understand that there is something more that needs to be done for solving this,
    if anyout out there knows the solution, please send me the steps and I can proceed. Or a clue also would be sufficient.

    Thanks,
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Do you have user rights to create files on that directory?

    Also I noticed this line:
    File.CreateText ("\\\\192.168.4 8.125\\Shared") ;

    This will ALWAYS fail. You cannot create a text file in a root directory, you would need to do like:
    File.CreateText ("\\\\192.168.4 8.125\\SomeShar eName\\Shared") ;

    Comment

    • vickyvick
      New Member
      • Jul 2008
      • 4

      #3
      Hi Plater,

      Simple mistake did me in, that was the cause of the issue, I had introduced the FileIOPermissio n line and assert line, but overlooked the filecreate part.
      Now its working fine.

      Thanks a lot.

      Comment

      Working...