Connecting Tech Pros Worldwide Help | Site Map

Create a text file on a network path using C#

Newbie
 
Join Date: Jul 2008
Posts: 4
#1: Nov 12 '08
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;
FileIOPermission myPerm = new FileIOPermission(FileIOPermissionAccess.Write, "\\\\192.168.48.125\\Shared");
myPerm.Assert();
//new FileIOPermission(FileIOPermissionAccess.Write, finfo.Directory.FullName).Demand();
SW1 = File.CreateText("\\\\192.168.48.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's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,150
#2: Nov 12 '08

re: Create a text file on a network path using C#


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

Also I noticed this line:
File.CreateText("\\\\192.168.48.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.48.125\\SomeShareName \\Shared");
Newbie
 
Join Date: Jul 2008
Posts: 4
#3: Nov 13 '08

re: Create a text file on a network path using C#


Hi Plater,

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

Thanks a lot.
Reply