i using httphandle in asp.net
when upload in mozila file uploaded but ie 7,8,9 not uploaded .
when trace my code in mozila or ie
give me this errorr.
'(postedFile.InputStream).ReadTimeout' threw an exception of type 'System.InvalidOperationException'
qustion: why top code this error ?
i solved this problem by this code . now work fine in ie 7,8,9 and mozilla .
public
class
uploader : IHttpHandler
{
public
void
ProcessRequest(HttpContext context)
{
try
{
if
(!
string
.IsNullOrEmpty(context.Request.QueryString[
"upload"
]))
{
HttpPostedFile postedFile = context.Request.Files[
"kendoFile1"
];
BufferedStream bs =
new
BufferedStream(postedFile.InputStream);
int
length = System.Convert.ToInt32(bs.Length);
byte
[] zipFile =
new
byte
[length];
int
offset = 0;
int
remaining = length;
while
(remaining != 0)
{
int
read = bs.Read(zipFile, offset, remaining);
if
(read <= 0)
throw
new
EndOfStreamException(String.Format(
"End of stream reached with {0} bytes left to read"
, remaining));
remaining -= read;
offset += read;
}
string
filepath = context.Server.MapPath(
"../test"
);
string
filename = postedFile.FileName.Split(
'\\')[postedFile.FileName.Split('
\\').Count() - 1];
if
(!Directory.Exists(filepath))
Directory.CreateDirectory(filepath);
if
(!(File.Exists(Path.Combine(filepath, filename))))
{
File.Create(Path.Combine(filepath, filename)).Close() ;
}
File.WriteAllBytes(Path.Combine(filepath, filename), zipFile);
context.Response.StatusCode = (
int
)HttpStatusCode.OK;
}
else
if
(!
string
.IsNullOrEmpty(context.Request.QueryString[
"remove"
]))
{
string
filepath = context.Server.MapPath(
"../test"
);
string
filename = context.Request.Form[
"fileNames"
];
FileInfo file =
new
FileInfo(Path.Combine(filepath, filename));
file.Delete();
context.Response.StatusCode = (
int
)HttpStatusCode.OK;
}
}
catch
(Exception ex)
{
context.Response.StatusCode = (
int
)HttpStatusCode.InternalServerError;
}
}
public
bool
IsReusable
{
get
{
return
false
;
}
}
}
thanks