473,387 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

webfolders

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
}
Nov 22 '05 #1
1 1119
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" <an*******@discussions.microsoft.com> wrote in message
news:8E**********************************@microsof t.com...
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;
}

Nov 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: cooldv | last post by:
i learnt from *Ken Schaefer's* website that for security reasons, u should put your DB outside the website root directory. this is his webpage -...
1
by: steve | last post by:
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,...
6
by: wASP | last post by:
Hello everyone, I'm new to C# and ASP.NET, so pardon my stupidity on this one. I'm having a problem with referencing methods/functions external to a class member function. My code is as...
8
by: Paul.Hawkes | last post by:
Hello, I've written a windows service and so far what it does is browse to a shared directory on an extranet. Check to see if any files exist in this folder, if any do, the service downloads,...
6
by: Andrei Pociu | last post by:
I saw a few people on the web having this problem, yet no solution. Validation using RequiredFieldValidator works fine on my server, but on some other server it doesn't do anything. Oh, and I'm...
1
by: treelife | last post by:
I'm getting and internal server error when | run the following mod_python script. I am actually trying to run Django. Script: from mod_python import apache def handler(req):...
14
by: robert | last post by:
For testing purposes I'm looking for a simple DAV server - best a python thing serving a folder tree. Don't want to install/change/setup the complex apache dav .. Found PyDav...
0
by: none | last post by:
Hi, I've got a problem with losing session state in ASP.NET version 2. It does it intermittently - sometimes it tanks - and sometimes it works OK. I've got the ASP.NET state service started...
1
by: alexey.yakovlev | last post by:
Hi, please read this before...
1
by: greeninsight | last post by:
I've used Common Dialog Box in my VB6 program to let user browse to a desired file. However we use MS-Sharepoint to store many of our documents, so we reference them through MyNetworkPlaces which...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.