Monie corleone
Monie corleone

Reputation: 1618

Write file to URL Location using c#

I want to write a file to a virtual directory path in same cloud.

For writing files to local we use

File.WriteAllText('c:\temp\sample.text',string)

Similarly, i want to write to network system like.

File.WriteAllText('\\\10.11.144.29\e$\projects\Map.text',string)

And to virtual directory location like.

File.WriteAllText('http://10.11.144.29/map/test.svg',string)

Is it possible to to write to URL location using c#? if possible, What class can be used?

Any help will be appreciated.

Upvotes: 2

Views: 4857

Answers (3)

VladL
VladL

Reputation: 13043

WebClient client = new WebClient();
//client.Credentials = new NetworkCredential("username", "password");
client.UploadFile("http://10.11.144.29/map/test.svg","test.svg");

Upvotes: 3

sreejithsdev
sreejithsdev

Reputation: 1210

File.WriteAllText(Server.MapPath(@"c:\temp\sample.text"),string).*

Upvotes: 0

Jamie Howarth
Jamie Howarth

Reputation: 3323

The last option isn't possible as you require an HTTP PUT or POST to be able to send binary data to a URL, using the HttpWebClient classes or similar.

Examples #1 and #2 you gave should be just fine, though, providing the code running has sufficient permissions at the given network location (i.e. write access)

Upvotes: 0

Related Questions