webfolders

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to read and write files in a web folder. I've succeeded in downloading a file from a web folder using the following code. However, I'm unsure as how to copy a file up to the server
Also, is there a way to determine the file attributes without downloading the file etc

private bool CopyFileFromWeb(string from, string to, int bufferSize

bool bOK = false
FileStream file = null
WebRequest req = WebRequest.Create(from)
try

WebResponse result = req.GetResponse()
Stream ReceiveStream = result.GetResponseStream()

Byte[] read = new Byte[bufferSize]
int bytes = ReceiveStream.Read(read, 0, bufferSize)

// open the destination strea
file = new FileStream(to,FileMode.CreateNew,FileAccess.Write)

while (bytes > 0

file.Write(read,0,bytes)
bytes = ReceiveStream.Read(read, 0, bufferSize)

bOK = true
}
catch(Exception exc)

// deal with error her

finall

if (file != null
file.Close()

return bOK
}
 
Take a look at the WebClient class. It has download and upload methods. You
can also send an HTTP HEAD request with HttpWebRequest to get the header
info containing file attributes.

--
Provided by the Microsoft PSfD UK team.
This posting is provided "AS IS" with no warranties, and confers no rights.
steve said:
I'm trying to read and write files in a web folder. I've succeeded in
downloading a file from a web folder using the following code. However, I'm
unsure as how to copy a file up to the server.
Also, is there a way to determine the file attributes without downloading the file etc.

private bool CopyFileFromWeb(string from, string to, int bufferSize)
{
bool bOK = false;
FileStream file = null;
WebRequest req = WebRequest.Create(from);
try
{
WebResponse result = req.GetResponse();
Stream ReceiveStream = result.GetResponseStream();

Byte[] read = new Byte[bufferSize];
int bytes = ReceiveStream.Read(read, 0, bufferSize);

// open the destination stream
file = new FileStream(to,FileMode.CreateNew,FileAccess.Write);

while (bytes > 0)
{
file.Write(read,0,bytes);
bytes = ReceiveStream.Read(read, 0, bufferSize);
}
bOK = true;
}
catch(Exception exc)
{
// deal with error here
}
finally
{
if (file != null)
file.Close();
}
return bOK;
}
 
Back
Top