A
Asshen Shugar
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;
}
}
}
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;
}
}
}