من مدتيه روي موضوع اين تاپيك دارم كار مي كنم
يه سري مشكلات دارم:
1. اگه فايل آپلود شده بزرگتر از 48KB يا همون PreloadedEntityBody باشه Browser در حالت آپلود ميمونه و اتفاقي نمي افته و وقتي stop زده بشه همون 48kb آپلود ميشه!
2. علاوه بر محتويات فايل، مقادير ViewState, كنترلهاي صفحه و ... هم درون فايل آپلود شده قرار ميگيره. نحوه جداسازي فايل از بقيه عناصر رو موفق نشدم عملي كنم
كدهايي كه زدم رو قرار ميدم
دوستان لطف مي كنن ايرادهاشو بهم بگن
HttpApplication application = (HttpApplication)sender;
HttpWorkerRequest request = (HttpWorkerRequest)application.Context.GetType().G etProperty("WorkerRequest", (BindingFlags)36).GetValue(application.Context, null);
if (application.Context.Request.ContentType.IndexOf(" multipart/form-data") > -1)
{
string guid = Guid.NewGuid().ToString();
string filename = application.Context.Server.MapPath("./") + guid + ".tmp";
if (request.HasEntityBody())
{
int content_length = Convert.ToInt32(request.GetKnownRequestHeader(Http WorkerRequest.HeaderContentLength));
int content_received = 0;
FileStream newFile = new FileStream(filename, FileMode.Create);
byte[] body = request.GetPreloadedEntityBody();
content_received += body.Length;
newFile.Write(body, 0, body.Length);
if (!request.IsEntireEntityBodyIsPreloaded())
{
byte[] a_buffer = new byte[1024];
int bytes_read = 1024;
while ((content_length - content_received) >= bytes_read)
{
bytes_read = request.ReadEntityBody(a_buffer, a_buffer.Length);
content_received += bytes_read;
newFile.Write(a_buffer, 0, bytes_read);
newFile.Flush();
}
bytes_read = request.ReadEntityBody(a_buffer, (content_length - content_received));
newFile.Write(a_buffer, 0, bytes_read);
content_received += bytes_read;
}
newFile.Close();
}
}