469,330 Members | 1,322 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,330 developers. It's quick & easy.

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;
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,
Nov 12 '08 #1
2 21588
Plater
7,872 Expert 4TB
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");
Nov 12 '08 #2
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.
Nov 13 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Yama | last post: by
5 posts views Thread by Michael Sperlle | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.