The main contents of this article include:
1, how to solve the file upload size limit
2. Save to server in file form
3. Convert to binary byte stream save to database and download method
4, upload resources on the Internet
The first part:
First, let's say how to solve the problem of file upload size limit in asp.net, we know that by default asp.net file upload size is limited to 2M, in general, we can use the change Web.config file to customize the maximum file size, as follows:
Copy Code code as follows:
The maximum size of the uploaded file becomes 4M, but this does not allow us to extend the maxRequestLength value indefinitely because ASP.net will load all the files into memory and then process them. The solution is to use the implied httpworkerrequest, using its getpreloadedentitybody and Readentitybody methods to read data in chunks from the pipe created by IIS for asp.net. The implementation method is as follows:
Copy Code code as follows:
Iserviceproviderprovider= (IServiceProvider) httpcontext.current;
Httpworkerrequestwr= (HttpWorkerRequest) provider. GetService (typeof (HttpWorkerRequest));
Byte[]bs=wr. Getpreloadedentitybody ();
.
if (!WR. Isentireentitybodyispreloaded ())
{
intn=1024;
Byte[]bs2=newbyte[n];
while (WR. Readentitybody (bs2,n) >0)
{
..
}
}
This will solve the problem of uploading large files.
Part II:
Here's how to upload a file from a client to a server
Copy Code code as follows:
public class FileUpload
{
Public FileUpload ()
{
}
/**/
<summary>
Upload file name
</summary>
public string FileName
{
Get
{
return fileName;
}
Set
{
FileName = value;
}
}
private string FileName;
/**/
<summary>
Upload file path
</summary>
public string FilePath
{
Get
{
return filepath;
}
Set
{
filepath = value;
}
}
private string filepath;
/**/
<summary>
File name extension
</summary>
public string FileExtension
{
Get
{
return fileextension;
}
Set
{
FileExtension = value;
}
}
private string fileextension;
}
current 1/2 page 1 2 Next read the full text