472,956 Members | 2,605 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Question about uploading file to asp script

Hi

My application is uploading the file to the ASP script. I am dealing
with situation where ASP script is not interested in receiving a file.
I simulate this by returning from ASP script:

protected void Page_Load(object sender, EventArgs e)
{
return
}

Then I am having difficulties in detecting such a situation on the
client side. The problem is that client is writing the file into the
buffer anyways. I tried closing Request.InputStream. Would appreciate
any help. Here is the client side code:

req = WebRequest.Create(url);
req.Method = "POST";

//Headers
req.ContentType = "multipart/form-data";
req.ContentLength = fileSize;
req.Headers.Add("Name", file.Name);
req.Headers.Add("Path", path);
req.Headers.Add("SessionID", session);
req.Timeout = int.MaxValue;

Stream stream = req.GetRequestStream();

using (BinaryWriter writer = new BinaryWriter(stream))
{
FileStream fs = new FileStream(file.FullName,
FileMode.Open);

using (BinaryReader reader = new BinaryReader(fs))
{
int i = 0;
long total = 0;

byte[] buffer = new byte[32768];

while (((i = reader.Read(buffer, 0,
buffer.Length)) 0) && !Stop)
{
writer.Write(buffer, 0, i);
total += i;
uploadWorker.ReportProgress((int)(total *
100 / fileSize));
}
}
}

Kind Regards
PK
Aug 9 '08 #1
1 1396
"Piotrekk" <Pi*************@gmail.comwrote in message
news:d9**********************************@z72g2000 hsb.googlegroups.com...
Hi

My application is uploading the file to the ASP script. I am dealing
with situation where ASP script is not interested in receiving a file.
I simulate this by returning from ASP script:

protected void Page_Load(object sender, EventArgs e)
{
return
}

Then I am having difficulties in detecting such a situation on the
client side. The problem is that client is writing the file into the
buffer anyways. I tried closing Request.InputStream. Would appreciate
any help. Here is the client side code:

req = WebRequest.Create(url);
req.Method = "POST";

//Headers
req.ContentType = "multipart/form-data";
req.ContentLength = fileSize;
req.Headers.Add("Name", file.Name);
req.Headers.Add("Path", path);
req.Headers.Add("SessionID", session);
req.Timeout = int.MaxValue;

Stream stream = req.GetRequestStream();

using (BinaryWriter writer = new BinaryWriter(stream))
{
FileStream fs = new FileStream(file.FullName,
FileMode.Open);

using (BinaryReader reader = new BinaryReader(fs))
{
int i = 0;
long total = 0;

byte[] buffer = new byte[32768];

while (((i = reader.Read(buffer, 0,
buffer.Length)) 0) && !Stop)
{
writer.Write(buffer, 0, i);
total += i;
uploadWorker.ReportProgress((int)(total *
100 / fileSize));
}
}
}
Not really a C# question.

What is unclear is whether the client code is expecting or can be modified
to expect an exception as a result of the server rejecting the POST.

You need to be sending back a non-200 response status to the client.
Probably the best match would be 405 Method Not Allowed. That should cause
the HttpRequest or the stream it returns to thrown an exception. Belts and
braces you can close the server-side to the Request connection.
--
Anthony Jones - MVP ASP/ASP.NET
Aug 10 '08 #2

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

Similar topics

6
by: Chamomile | last post by:
can anyone point me to some straightforward information on file uploading without using an html form? That is, direcly from within a php script. if I know the local path etc. to a particular...
1
by: Pamela Chatterjee | last post by:
In my project I am uploading file, using HttpPostedFile in ASP.NET. In my project I have to allow user to upload pdf, gif and jepg file only. I know after uploading file I can check ContentType of ...
4
by: msnews.microsoft.com | last post by:
Hi, I hope we can upload only files with limited size through ASP scripts(<2MB). I need to write an ASP script that can serve up to 100MB of file uploading. I have written one script(with...
9
by: CGW | last post by:
I asked the question yesterday, but know better how to ask it, today: I'm trying to use the File.Copy method to copy a file from a client to server (.Net web app under IIS ). It looks to me that...
3
by: Dean Richardson | last post by:
Hi, I'm having trouble uploading files via a PHP script. Whenever I upload a file greater than 10K, the file gets corrupted. However, text files upload OK. When I check the FTP Server log I...
5
by: Chris | last post by:
I have a meetings section I'm developing on our intranet. Using PHP/MySQL. Meeting info and Meeting docs reside on 2 related tables in the db. Users may want to upload anywhere from 1 to 10 or...
3
by: MichaelK | last post by:
Looking for sample of Upload file asp code. If possible with the checking of file type and size before starting uploading. Thanks in advance, Michael
3
chunk1978
by: chunk1978 | last post by:
hi there... i have a form where a user may optionally upload a maximum of 2 files along with other textual data (there are 2 file fields built in the form). i'm having trouble writing a php script...
11
by: starter08 | last post by:
Hi, I have a C++ function which sends a post request to a server for uploading a file. I have also written a server side cgi to receive the data and create the file in a specified directory. The...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.