Wednesday, March 28, 2012

Installed AJAX - cannot upload large files

Hello there.
I have an issue with file size to be uploaded that happened only after I installed AJAX.

So before installing AJAX on the web server, we did set on the web.config of our application the following value
<httpRuntime maxRequestLength=30000 /> which did allow us to upload files up to 30 MG.

After we installed AJAX, it seems that we are not capable to upload large files again.

Do you know if AJAX installation may override somehow that value somewhere else?
The web.config of our application still has the 30000 entry ...but it is obviously not working any longer.

Filippo

If the file upload is now inside an ajax control, it may be that you're hitting a script-timeout (i.e. XMLHTTPREQUEST times out before the whole file can be uploaded.)

You're best bet would be to run the file upload outside of an ajax control - i.e. as a proper postback.

p.s. It should be 30720 for 30 MB - in case you're publishing the maximum size it could confuse people.


thank you , but I'm not using AJAX in my upload page

I use just put Scriptmanager in the master page/? is this makes problems ?

by the way it was working well up to 10MB but when I changed the server it upload the file with 0kb even it's 5MB

so is this mistake of server (it's local server indeed) I want to be ensure that the code is ok

here is my upload function

1public string DoImport(FileUpload myFileUpload)2 {3string ServerPath ="";4string webServerFilePath ="";5try6 {78string filepath = myFileUpload.PostedFile.FileName;910if ((filepath !=null) & (filepath.Length != 0))11 {12 FileInfo finfo =new FileInfo(filepath);13string filename = finfo.Name;14//save file on the webserver machine1516 StringBuilder bufWebServerFilePath =new StringBuilder(240);17string tempImportFldr =18 Server.MapPath("~\\"19 + ConfigurationManager.ConnectionStrings["TempAttachPath"].ToString());20 bufWebServerFilePath.Append(tempImportFldr);21if (tempImportFldr.EndsWith("\\") ==false)22 {23 bufWebServerFilePath.Append("\\");24 }25 bufWebServerFilePath.Append(Session.LCID.ToString() + filename);/*to make file unique*/26 webServerFilePath = bufWebServerFilePath.ToString();272829if (File.Exists(webServerFilePath))30 {31 File.Delete(webServerFilePath);32 }3334 myFileUpload.SaveAs(webServerFilePath);3536 ServerPath = webServerFilePath;37 }383940 }41catch (Exception Ex)42 {43////this code is to write in a log file(Optional)44 CreateLogFiles.CreateLogFiles Err =new CreateLogFiles.CreateLogFiles();45string path = Request.PhysicalApplicationPath.ToString();46 Err.ErrorLog(Request.PhysicalApplicationPath.ToString() + ("Logs/ErrorLog"),"(" + ServerPath +")DoImport->(internal memo)" + Ex.Message);4748 }495051return ServerPath;52 }
the error message comes in line (36) ->Cannot access a closed file.
so any help please 
thanks in advance 

Well , I got it worked by adding this line in my web.config

<httpRuntime useFullyQualifiedRedirectUrl="true" maxRequestLength="250000" requestLengthDiskThreshold="250000"/>

No comments:

Post a Comment