473,387 Members | 1,687 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 1120
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.