Reputation: 71
I try to create a file in a server using the following code
String path = @"\\192.1.1.55\\d$:\\Scripts\\list.txt";
using (File.Create(path));
richTextBox1.SaveFile(path, RichTextBoxStreamType.PlainText);
It gives System.NotSupportedException The given path's format is not supported.
I also tried
String path = "\\\\192.1.1.55\\d$:\\Scripts\\list.txt";
using (File.Create(path));
richTextBox1.SaveFile(path, RichTextBoxStreamType.PlainText);
I need to create files and access them over the network with the ip of the server that has files,
Upvotes: 4
Views: 19737
Reputation: 3326
use the following code:
String path = "\\\\192.1.1.55\\d$\\Scripts\\list.txt";
using (File.Create(path));
richTextBox1.SaveFile(path, RichTextBoxStreamType.PlainText);
as per microsoft site:
The SaveFile method enables you to save the entire contents of the control to an RTF file that can be used by other programs such as Microsoft Word and Windows WordPad. If the file name that is passed to the path parameter already exists at the specified directory, the file will be overwritten without notice
I don't think there would be any need for the statement: using (File.Create(path)); Also, if you are using richtextbox. you should save it as list.rtf.
Upvotes: 0
Reputation: 7187
Remove the : after the D$ and it should work.
I now realized that you also have an @ at the beginning of the path string, therefore, change the path to this:
String path = @"\\192.1.1.55\d$\Scripts\list.txt";
A better approach would be to map the network path to a drive and to use that while saving.
For instance, map network drive R (for richtextbox) to \\192.1.1.55\d$, then change your path variable to G:\Scripts\list.txt
Upvotes: 1