Writing to a file

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
 
K

Kevin Spencer

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.
 
S

Scott

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.
 
K

Kevin Spencer

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.
 
S

spalding

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top