Rank: Member Groups: Member
Joined: 4/12/2006 Posts: 6 Points: 0
|
Hi Fedor We are migrating our application from .NET 1.1 to .NET 2.0 The ImageUploader component worked fine in the previous version but in the new version when I try to upload large images the application is throwing error: Code:ex.Message: Cannot access a closed file. e.StackTrace: at System.IO.__Error.FileNotOpen() at System.IO.FileStream.Seek(Int64 offset, SeekOrigin origin) at System.Web.HttpRawUploadedContent.TempFile.GetBytes(Int32 offset, Int32 length, Byte[] buffer, Int32 bufferOffset) at System.Web.HttpRawUploadedContent.WriteBytes(Int32 offset, Int32 length, Stream stream) at System.Web.HttpInputStream.WriteTo(Stream s) at System.Web.HttpPostedFile.SaveAs(String filename) at korthuset_net.aspSmartUpload1.uploadLogics(String dirPath, HttpPostedFile sourceFile, HttpPostedFile thumbFile) in d:\\Projects\\KorthusetWeb-TESTING\\aspSmartUpload1.aspx.cs:line 236" The code that we use is: Code:
protected override void Page_Load(object sender, System.EventArgs e)
{
base.Page_Load (sender, e);
int intFileCount = Int32.Parse(Request.Form["FileCount"]);
string strGalleryPath = @"C:\\Gallery"
if(!Directory.Exists(strGalleryPath ))
Directory.CreateDirectory(strGalleryPath );
if(!Directory.Exists(strGalleryPath + "\\Thumbnails"))
Directory.CreateDirectory(strGalleryPath + "\\Thumbnails");
dirPath = strGalleryPath +"\\";
for (int i = 1; i <= intFileCount; i++)
{
sourceFile = Request.Files["SourceFile_1"];
thumbFile = Request.Files["Thumbnail1_1"];
tr = new Thread(new ThreadStart(this.NewThread));
tr.Start();
}
}
private void NewThread()
{
try
{
uploadLogics(dirPath, sourceFile, thumbFile);
}
catch (Exception ex)
{
string exp = ex.Message;
}
finally
{
tr.Abort();
}
}
private void uploadLogics(string dirPath, HttpPostedFile sourceFile, HttpPostedFile thumbFile)
{
string fileName;
string ext;
long size;
fileName = Path.GetFileName(sourceFile.FileName);
ext = fileName.Substring(fileName.LastIndexOf("."));
fileName = fileName.Substring(0, fileName.LastIndexOf("."));
bool tif = false;
if (ext.ToLower().Equals(".tif") || ext.ToLower().Equals(".tiff"))
{
ext = ".jpg";
tif = true;
}
fileName = Regex.Replace(fileName, @"[ ',;+%]", "_");
string newFileName = fileName + ext;
int j = 1;
while (File.Exists(dirPath + newFileName))
{
newFileName = j + "_" + fileName + ext;
j++;
}
ext = newFileName.Substring(newFileName.LastIndexOf("."));
fileName = newFileName.Substring(0, newFileName.LastIndexOf("."));
fileName = fileName.Length > 50 ? fileName.Substring(0, 50) : fileName;
try
{
if (tif)
{
ext = ".jpg";
System.Drawing.Image im = System.Drawing.Image.FromStream(sourceFile.InputStream);
im.Save(dirPath + fileName + ".jpg", ImageFormat.Jpeg);
im.Dispose();
}
else
{
sourceFile.SaveAs(dirPath + fileName + ext);
}
size = sourceFile.InputStream.Length;
thumbFile.SaveAs(dirPath + "Thumbnails\\" + fileName + ext);
}
catch (Exception ex)
{
string message = ex.Message;
string stack = ex.StackTrace;
}
}
The ImageUploader is configured like this: Code:
var iu = new ImageUploaderWriter("ImageUploader", 650, 350);
iu.activeXControlEnabled = true;
iu.javaAppletEnabled = true;
iu.activeXControlCodeBase = "ImageUploader4.cab";
iu.javaAppletCodeBase="./";
iu.addParam("PaneLayout", "TwoPanes");
iu.addParam("BackgroundColor", "#ffffff");
iu.addParam("UploadThumbnail1FitMode", "Fit");
iu.addParam("UploadThumbnail1Width", "120");
iu.addParam("UploadThumbnail1Height", "120");
iu.addParam("UploadThumbnail1JpegQuality", "60");
iu.addParam("FilesPerOnePackageCount", "1");
iu.addParam("AutoRecoverMaxTriesCount", "5");
iu.addParam("AutoRecoverTimeOut", "1200");
iu.addParam("ShowDebugWindow", "True");
iu.addParam("AdditionalFormName", "Form1");
iu.addParam("AllowRotate", "False");
iu.addParam("Action", "aspSmartUpload1.aspx");
iu.addParam("FileMask", "*.jpg;*.bmp;*.tiff;*.tif");
iu.addParam("MaxFileSize", "5242880");
iu.addParam("ButtonStopText", "<%=languageText["bStop"]%>");
iu.addParam("ShowDescriptions", "0");
iu.addParam("CheckFilesBySelectAllButton", "True");
iu.addEventListener("Progress", "ImageUploaderID_Progress");
iu.writeHtml();
function ImageUploaderID_Progress(Status, Progress, ValueMax, Value, StatusText)
{
if (Status=="COMPLETE")
{
tt = window.setTimeout("doAction()",2000);
}
if (Status=="CANCEL")
{
tt = window.setTimeout("doAction()",2000);
}
}
The problem is occuring only with large images like images with sizes > 3MB for example, but with small size images 20, 50, 90 KB everything is OKCan you please help me with this problem ASAP? Thanks in advance Zoki
|
 Rank: Advanced Member Groups: Member
Joined: 8/3/2003 Posts: 996 Points: 1
|
Hello, Please see new ASP.NET 2.0 RequestLengthDiskThreshold property of HttpRuntime web.config section. You should set appropriate value for your purposes (for example to 8192). It seems that ASP.NET 2.0 allows about 200kb temporary files only. Also you should set Page.EnableEventValidation property to False value. Please see the discussion of the same issue on ASP.NET Forums.
Sincerely yours, Alex Makhov
|