I have written the following code for creating a file and it works fine...

string dirAddress = "C:\\FTPTrace\\" + ipHeader.DestinationAddress.ToString() + ".txt";

System.IO.StreamWriter logfile = new StreamWriter(dirAddress,true);

Now I want to add ip address of the local machine in the path... as...


string dirAddress = "\\192.168.15.96\\C:\\FTPTrace\\" + ipHeader.DestinationAddress.ToString() + ".txt";

but it raises the exception "A first chance exception of type 'System.NotSupportedException' occurred in mscorlib.dll"

Kindly guide me where am i wrong... ??

Plz help...

The drive letter will always need to come first IF your intention is to write it to a mapped drive.
Is the IP address part supposed to be a directory or part of the file name?
...or something else?

Check to ensure that \\192.168.15.96\C:\FTPTrace is accessible through windows explorer. I can guarantee that it isn't. You can't have a ':' in a network path after a drive number - try sharing your C drive - then try naming the share "C:" instead of the default "C". It doesn't work!

The drive letter will always need to come first IF your intention is to write it to a mapped drive.
Is the IP address part supposed to be a directory or part of the file name?
...or something else?

IP address is part of the file name... just as the drive is part of the
file name...

Like skatamatic said, the share name for the C:\ drive on the remote machine will not be C: (it is probably something like C$ or C). Check the remote machine to ensure it is sharing the C:\ drive, what its share name is, and the permissions (right-click -> properties -> sharing etc.). Also, you need 2 backslashes in front of a network address, since \\ is an escape character you could either do:

string dirAddress = "\\\\192.168.15.96\\C$\\FTPTrace\\" + ipHeader.DestinationAddress.ToString() + ".txt";

or:

string dirAddress = @"\\192.168.15.96\C$\FTPTrace\" + ipHeader.DestinationAddress.ToString() + ".txt";

Well, if it actually is on a remote machine and the current user has permission to the C drive (sharing is ebabled on the C drive), that will work.
You could also map a network drive to that location.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.