Hey.
I was experimenting with file uploading possibility using ASP.NET.
I ran into a problem :(
I can upload small files, but if I try a bigger file it doesn't work...
Anyone who can help me please ?
Thanks.
K.
private void btnUpload_Click(object sender, System.EventArgs e)
{
string strBaseLocation = Server.MapPath( "./files" );
if ( txtUploadFile.Value == string.Empty )
{
lblInfo.Text = "Gelieve een bestand te selecteren.";
return;
}
string fileName = GetFileName( txtUploadFile.Value );
string fileTarget = strBaseLocation + "\\" + fileName;
if (null != txtUploadFile.PostedFile)
{
try
{
//read/write buffer
const int BUFFER_SIZE = 255;
Byte[] Buffer = new Byte[BUFFER_SIZE];
lblInfo.Text = "Uploading File: " + fileName;
//incoming external file stream
Stream theStream = txtUploadFile.PostedFile.InputStream;
//local file stream
FileStream fs = new FileStream(fileTarget, FileMode.CreateNew,
FileAccess.Write);
//local binary writer on local file stream
BinaryWriter bw = new BinaryWriter(fs);
// read/write loop
while( theStream.Read(Buffer, 0, BUFFER_SIZE) != 0 )
{
bw.Write(Buffer, 0, BUFFER_SIZE);
}
//Close the streams
bw.Close();
fs.Close();
theStream.Close();
lblInfo.Text = "Upload finished.";
//reload directory listing
FindAndDisplayFiles();
}
catch(Exception ex)
{
lblInfo.Text = "Fout bij het uploaden.<br>" + ex.Message;
}
}
} 15 1757
k, already found that httpRunTime defaults to max 4000 kb...
<configuration>
<system.web>
<httpRuntime maxRequestLength="4000"
useFullyQualifiedRedirectUrl="true"
executionTimeout="45"
versionHeader="1.1.4128"/>
</system.web>
</configuration>
How do I change it ?
Thank you.
K.
"Asshen Shugar" <va********@hotmail.com> wrote in message
news:6H*********************@phobos.telenet-ops.be... Hey.
I was experimenting with file uploading possibility using ASP.NET. I ran into a problem :(
I can upload small files, but if I try a bigger file it doesn't work...
Anyone who can help me please ?
Thanks. K.
private void btnUpload_Click(object sender, System.EventArgs e) { string strBaseLocation = Server.MapPath( "./files" );
if ( txtUploadFile.Value == string.Empty ) { lblInfo.Text = "Gelieve een bestand te selecteren."; return; }
string fileName = GetFileName( txtUploadFile.Value ); string fileTarget = strBaseLocation + "\\" + fileName;
if (null != txtUploadFile.PostedFile) { try { //read/write buffer const int BUFFER_SIZE = 255; Byte[] Buffer = new Byte[BUFFER_SIZE]; lblInfo.Text = "Uploading File: " + fileName;
//incoming external file stream Stream theStream = txtUploadFile.PostedFile.InputStream;
//local file stream FileStream fs = new FileStream(fileTarget, FileMode.CreateNew, FileAccess.Write);
//local binary writer on local file stream BinaryWriter bw = new BinaryWriter(fs);
// read/write loop while( theStream.Read(Buffer, 0, BUFFER_SIZE) != 0 ) { bw.Write(Buffer, 0, BUFFER_SIZE); }
//Close the streams bw.Close(); fs.Close(); theStream.Close();
lblInfo.Text = "Upload finished.";
//reload directory listing FindAndDisplayFiles(); } catch(Exception ex) { lblInfo.Text = "Fout bij het uploaden.<br>" + ex.Message; } } }
Asshen Shugar wrote: <httpRuntime maxRequestLength="4000" How do I change it ?
You, uhh... change it. What happened when you tried?
I can upload files of a maximum size of 4000 kB.
That's the default maximum size specified in Machine.config.
I tried to add the <httpRuntime> node in the Web.config of my project, but
that doesn't work (guess machine.config has greater permission than on
application level ?).
So the only solution I see is changing the machine.config file ?
Is that correct ?
K
"jasonkester" <ja*********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com... Asshen Shugar wrote: <httpRuntime maxRequestLength="4000" How do I change it ?
You, uhh... change it. What happened when you tried?
Asshen Shugar wrote: I can upload files of a maximum size of 4000 kB. That's the default maximum size specified in Machine.config.
I tried to add the <httpRuntime> node in the Web.config of my
project, but that doesn't work (guess machine.config has greater permission than
on application level ?).
So the only solution I see is changing the machine.config file ? Is that correct ?
Strange. I ran into the same limitation recently, and the following
web.config fixed it:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<httpRuntime maxRequestLength="102400" executionTimeout="600" />
</system.web>
</configuration>
Note that that's the entire web.config file for the directory that
needs it. I'd be hesitant to modify the web.config at the root of your
application, since you don't want to allow your users to routinely hit
you with 10mb requests.
Incedentally, the machine.config on our servers has the following line,
and the web.config above still allows large file downloads:
<httpRuntime executionTimeout="90" maxRequestLength="4096"
useFullyQualifiedRedirectUrl="false" minFreeThreads="8"
minLocalRequestFreeThreads="4" appRequestQueueLimit="100"
enableVersionHeader="true"/>
Jason Kester
Expat Software Consulting Services http://www.expatsoftware.com/
Asshen Shugar wrote: I can upload files of a maximum size of 4000 kB. That's the default maximum size specified in Machine.config.
I tried to add the <httpRuntime> node in the Web.config of my
project, but that doesn't work (guess machine.config has greater permission than
on application level ?).
So the only solution I see is changing the machine.config file ? Is that correct ?
Strange. I ran into the same limitation recently, and the following
web.config fixed it:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<httpRuntime maxRequestLength="102400" executionTimeout="600" />
</system.web>
</configuration>
Note that that's the entire web.config file for the directory that
needs it. I'd be hesitant to modify the web.config at the root of your
application, since you don't want to allow your users to routinely hit
you with 10mb requests.
Incedentally, the machine.config on our servers has the following line,
and the web.config above still allows large file uploads:
<httpRuntime executionTimeout="90" maxRequestLength="4096"
useFullyQualifiedRedirectUrl="false" minFreeThreads="8"
minLocalRequestFreeThreads="4" appRequestQueueLimit="100"
enableVersionHeader="true"/>
Jason Kester
Expat Software Consulting Services http://www.expatsoftware.com/
Ok, thanks.
I'll look into it tomorrow.
Greetings.
K.
"jasonkester" <ja*********@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com... Asshen Shugar wrote: I can upload files of a maximum size of 4000 kB. That's the default maximum size specified in Machine.config.
I tried to add the <httpRuntime> node in the Web.config of my project, but that doesn't work (guess machine.config has greater permission than on application level ?).
So the only solution I see is changing the machine.config file ? Is that correct ?
Strange. I ran into the same limitation recently, and the following web.config fixed it:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.web> <httpRuntime maxRequestLength="102400" executionTimeout="600" /> </system.web> </configuration>
Note that that's the entire web.config file for the directory that needs it. I'd be hesitant to modify the web.config at the root of your application, since you don't want to allow your users to routinely hit you with 10mb requests.
Incedentally, the machine.config on our servers has the following line, and the web.config above still allows large file uploads:
<httpRuntime executionTimeout="90" maxRequestLength="4096" useFullyQualifiedRedirectUrl="false" minFreeThreads="8" minLocalRequestFreeThreads="4" appRequestQueueLimit="100" enableVersionHeader="true"/>
Jason Kester Expat Software Consulting Services http://www.expatsoftware.com/
I have an extra question...
Is it possible to find the filesize of the file that a client wants to
upload before it is getting uploaded ?
K.
"Asshen Shugar" <va********@hotmail.com> wrote in message
news:6H*********************@phobos.telenet-ops.be... Hey.
I was experimenting with file uploading possibility using ASP.NET. I ran into a problem :(
I can upload small files, but if I try a bigger file it doesn't work...
Anyone who can help me please ?
Thanks. K.
private void btnUpload_Click(object sender, System.EventArgs e) { string strBaseLocation = Server.MapPath( "./files" );
if ( txtUploadFile.Value == string.Empty ) { lblInfo.Text = "Gelieve een bestand te selecteren."; return; }
string fileName = GetFileName( txtUploadFile.Value ); string fileTarget = strBaseLocation + "\\" + fileName;
if (null != txtUploadFile.PostedFile) { try { //read/write buffer const int BUFFER_SIZE = 255; Byte[] Buffer = new Byte[BUFFER_SIZE]; lblInfo.Text = "Uploading File: " + fileName;
//incoming external file stream Stream theStream = txtUploadFile.PostedFile.InputStream;
//local file stream FileStream fs = new FileStream(fileTarget, FileMode.CreateNew, FileAccess.Write);
//local binary writer on local file stream BinaryWriter bw = new BinaryWriter(fs);
// read/write loop while( theStream.Read(Buffer, 0, BUFFER_SIZE) != 0 ) { bw.Write(Buffer, 0, BUFFER_SIZE); }
//Close the streams bw.Close(); fs.Close(); theStream.Close();
lblInfo.Text = "Upload finished.";
//reload directory listing FindAndDisplayFiles(); } catch(Exception ex) { lblInfo.Text = "Fout bij het uploaden.<br>" + ex.Message; } } }
Asshen what you can also do is to setup your web.config for the specific
folders.
Patrick
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
On Wed, 23 Mar 2005 17:28:34 GMT, "Asshen Shugar"
<va********@hotmail.com> wrote:
I can't help you on the answer but how many people pick up on the
Valheru reference? One of my all time favorite stories.
Raymond Feist fan ?
Hehe, yeah great books aren't it :)
K.
"dgk" <so******************@hot-nospamp-mail.com> wrote in message
news:i4********************************@4ax.com... On Wed, 23 Mar 2005 17:28:34 GMT, "Asshen Shugar" <va********@hotmail.com> wrote:
I can't help you on the answer but how many people pick up on the Valheru reference? One of my all time favorite stories.
Asshen Shugar wrote: I have an extra question... Is it possible to find the filesize of the file that a client wants
to upload before it is getting uploaded ?
Careful. You're getting into the realm where we're going to start
asking 'What did you Try?' and shut down on you. If you typed
"myFileInputControl." and hit ctrl-space, you'd quickly find
PostedFile.ContentLength.
That will give you the content length of whatever your user is trying
to send you. If you like it, you can hook a fileStream up to it and
suck it down. If you don't, you can boot him to an error page with no
bandwidth wasted at your end.
Jason Kester
Expat Software Consulting Services http://www.expatsoftware.com/
I tried that already.
Seems like I can't get the file size (ContentLength) until it is already
being uploaded (and get the resulting error page) !
Trust me, I did my research before asking the question, just didn't find a
working answer, hence the question here.
K.
"jasonkester" <ja*********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com... Asshen Shugar wrote: I have an extra question... Is it possible to find the filesize of the file that a client wants to upload before it is getting uploaded ?
Careful. You're getting into the realm where we're going to start asking 'What did you Try?' and shut down on you. If you typed "myFileInputControl." and hit ctrl-space, you'd quickly find PostedFile.ContentLength.
That will give you the content length of whatever your user is trying to send you. If you like it, you can hook a fileStream up to it and suck it down. If you don't, you can boot him to an error page with no bandwidth wasted at your end.
Jason Kester Expat Software Consulting Services http://www.expatsoftware.com/
From MSDN:
Gets the size in bytes of an uploaded file.
[Visual Basic]
Public ReadOnly Property ContentLength As IntegerSo, it gets the file size
AFTER upload.
K.
"Asshen Shugar" <va********@hotmail.com> wrote in message
news:hl*********************@phobos.telenet-ops.be... I tried that already. Seems like I can't get the file size (ContentLength) until it is already being uploaded (and get the resulting error page) !
Trust me, I did my research before asking the question, just didn't find a working answer, hence the question here.
K.
"jasonkester" <ja*********@gmail.com> wrote in message news:11**********************@f14g2000cwb.googlegr oups.com... Asshen Shugar wrote: I have an extra question... Is it possible to find the filesize of the file that a client wants to upload before it is getting uploaded ?
Careful. You're getting into the realm where we're going to start asking 'What did you Try?' and shut down on you. If you typed "myFileInputControl." and hit ctrl-space, you'd quickly find PostedFile.ContentLength.
That will give you the content length of whatever your user is trying to send you. If you like it, you can hook a fileStream up to it and suck it down. If you don't, you can boot him to an error page with no bandwidth wasted at your end.
Jason Kester Expat Software Consulting Services http://www.expatsoftware.com/
Asshen Shugar wrote: I tried that already. Seems like I can't get the file size (ContentLength) until it is
already being uploaded (and get the resulting error page) !
That is exactly true. So your solution is to use the web.config
setting to open yourself up to the maximum size you'll reasonably
expect your users to want to send you, then use ContentLength to reject
files larger than you actually want to receive.
But at the end of the day, there's really no way to give out a pretty
error message to a user that tries to upload a 40GB file.
Jason Kester
Expat Software Consulting Services http://www.expatsoftware.com/
Ok, thank you very much.
I "investigated" this technique out of curiosity, but so on a professionel
level it would be better to advise some component I guess ?
K.
"jasonkester" <ja*********@gmail.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com... Asshen Shugar wrote: I tried that already. Seems like I can't get the file size (ContentLength) until it is already being uploaded (and get the resulting error page) !
That is exactly true. So your solution is to use the web.config setting to open yourself up to the maximum size you'll reasonably expect your users to want to send you, then use ContentLength to reject files larger than you actually want to receive.
But at the end of the day, there's really no way to give out a pretty error message to a user that tries to upload a 40GB file.
Jason Kester Expat Software Consulting Services http://www.expatsoftware.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: matt |
last post by:
I have compiled some code, some written by me, some compiled from
various sources online, and basically i've got a very simple flat file
photo gallery. An upload form, to upload the photos and give...
|
by: Bijoy Naick |
last post by:
I've written a simple file upload user control in VB .NET. It comprises of
an InputFile HTML Server Control, an Upload button and a message label.
User clicks on the Browse button of the...
|
by: tshad |
last post by:
I have an upload file input as:
<input id="MyFile" style="width:300px" type="File" runat="Server">
This works fine, but I find that if my page doesn't pass validation during
postback, the page...
|
by: Jen |
last post by:
I'm using Microsoft's own VB.NET FTP Example:
http://support.microsoft.com/default.aspx?scid=kb;en-us;832679
I can get the program to create directories, change directories, etc.,
but I can't...
|
by: Matt Jensen |
last post by:
Howdy
I've got a rather strange issue occuring.
I used forms based .NET authentication, although I'm also setting some
session variables when people login.
However, I've found when people use...
|
by: William LaMartin |
last post by:
I have a VB ASP.Net application where the user can upload a file using the
FileUpload server control. I also want a thumbnail to be created for this
file. Unfortunately I can see no means to...
|
by: riteshjain82 |
last post by:
Hi, Please go through this:
I am having a file (default.asp) on which i am taking many details from
a user before mailing it to someone. I have also provided the user with
a facility of...
|
by: Vic Spainhower |
last post by:
Hello,
I am trying to do a FTP file upload which works fine on my localhost but on
my ISP server it fails. I can't seem to find where I can go to find the
specific cause of the failure. In both...
|
by: pbd22 |
last post by:
hi.
i am having probs understanding how to grab a file being uploaded from
a remote client. i am using hidden input fields for upload such as:
<input id="my_file_element" type="file"...
|
by: pbd22 |
last post by:
hi.
i have been posting this here and elsewhere a lot and can't seem to get
resolution on this problem.
i have been trying to upload files using a hidden iframe to a
asp.net/vb.net form. the...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
| |