Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
zoki_57  
#1 Posted : Thursday, August 17, 2006 5:45:01 PM(UTC)
zoki_57

Rank: Member

Groups: Member
Joined: 4/11/2006(UTC)
Posts: 6

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);
			
	//Get total number of uploaded files
	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 +"\\";

	//We iterate through the uploaded files and save them and appropriate data
	for (int i = 1; i <= intFileCount; i++)
	{
	   //Get source image and save it to disk
                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;

            //get file name
            fileName = Path.GetFileName(sourceFile.FileName);

            ext = fileName.Substring(fileName.LastIndexOf("."));
            fileName = fileName.Substring(0, fileName.LastIndexOf("."));

            //if file is tif it will be saved as .jpg
            bool tif = false;
            if (ext.ToLower().Equals(".tif") || ext.ToLower().Equals(".tiff"))
            {
                ext = ".jpg";
                tif = true;
            }

            fileName = Regex.Replace(fileName, @"[ ',;+%]", "_");

            //if already was uploaded file with that name, the current file
            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("."));

            //shrink the file name to max 50 characters
            fileName = fileName.Length > 50 ? fileName.Substring(0, 50) : fileName;

            //save file 
            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;
                //Get first thumbnail (the single thumbnail in this code sample)
                thumbFile.SaveAs(dirPath + "Thumbnails\\" + fileName + ext);

                //database insert code.....
            }
            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 OK

Can you please help me with this problem ASAP?

Thanks in advance
Zoki

Edited by user Tuesday, February 19, 2008 1:00:20 PM(UTC)  | Reason: Not specified

Alex Makhov  
#2 Posted : Thursday, August 17, 2006 8:23:49 PM(UTC)
Alex Makhov

Rank: Advanced Member

Groups: Member
Joined: 8/3/2003(UTC)
Posts: 998

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.

Edited by user Tuesday, February 19, 2008 1:05:17 PM(UTC)  | Reason: Not specified

Sincerely yours,
Alex Makhov

UserPostedImage Follow Aurigma on Twitter!
Users browsing this topic
Similar Topics
Upload converted files into different folders Asp.Net 2.0 (Discussions – ActiveX/Java Uploader)
by sweetjos 9/25/2011 9:59:01 PM(UTC)
Dynamic folder selection Asp.net 2.0 VB (Discussions – ActiveX/Java Uploader)
by chris cee 1/28/2008 1:21:19 AM(UTC)
ASP.NET 2.0 Hosting Recommendation (Discussions – Graphics Mill)
by DJ 11/8/2007 11:56:35 AM(UTC)
INFO: ASP.NET 2.0 Cannot Find a Required Module when Loading Graphics Mill 3.x and 4.x DLLs. (FAQ – Graphics Mill)
by Fedor 12/6/2006 7:34:00 AM(UTC)
Heap size issues inside IIS 6/ASP.Net 2.0 (Discussions – Graphics Mill)
by grady 6/7/2006 11:23:46 AM(UTC)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.