Writing to a file

  • Thread starter Thread starter Scotty
  • Start date Start date
S

Scotty

I have a file on a server. How do I get a stream to
write to this file.

I can read this through the following

string filePath = "http:\\QuickServ1\TestLogs\Log.txt"

WebRequest req = System.Net.WebRequest.Create(filePath);
HttpWebRequest hreq = (System.Net.HttpWebRequest)req;
WebResponse res = hreq.GetResponse();
str = res.GetResponseStream();

//I Use this stream for reading the file

how write to this...


Thanks in advance
 
Imagine what life would be like if anyone could write to a file on a web
server in this way. Why, all hackers would have to do is write a little
utility like you're attempting, and change the contents of any file on any
web server in the world.

How to write that? NOT, Hopefully, NEVER.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Kevin,

I have very little experience in web development as I
am just starting in this area.I had been a windows
developer (in C#/VB.NET) before

I need to serialise an xml document to save an object
and as my company has a cluster of servers I am asked to
store that file on a shared server and not in the
application directory,hence the problem.

I would appreciate if you could give me any ideas as to
how I can access the shared server to serialise my xml
document.
 
Hi Scott,

You will have to use the File System, not a WebRequest. I am guessing that
there is a UNC path to the file. If you use that with the System.IO
NameSpace classes, you should be fine.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Scotty said:
*I have a file on a server. How do I get a stream to
write to this file.

I can read this through the following

string filePath = "http:\\QuickServ1\TestLogs\Log.txt"

WebRequest req = System.Net.WebRequest.Create(filePath);
HttpWebRequest hreq = (System.Net.HttpWebRequest)req;
WebResponse res = hreq.GetResponse();
str = res.GetResponseStream();

//I Use this stream for reading the file

how write to this...


Thanks in advance *

Hi

Is the file on the webserver, or is it on the network?

If it's on the webserver, use the StreamWriter class to open the fil
and write to it. If it's on the network, I assume you can use the sam
solution, just specify the network path (although I've never tried)


-
spaldin
 
Back
Top