Click here to Skip to main content
15,845,742 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I can Upload upto 600 KB file using the following code. If I want to upload file size more than this then following error occours:
The request was aborted: The request was canceled

I have already set following code on web.config

httpRuntime executionTimeout="6000" maxRequestLength="1097152"

Please suggest me, what can I do?

Code on Mobile app:
            String strFile = System.IO.Path.GetFileName(filename);

            // create an instance fo the web service
             service.DataService wser = new service.DataService();

            FileInfo fInfo = new FileInfo(filename);

            // to upload it (with the standard 4 MB limit)
            long numBytes = fInfo.Length;
            double dLen = Convert.ToDouble(fInfo.Length / 1000000);

            // Default limit of 4 MB on web server
            if (dLen < 100)
                // set up a file stream and binary reader for the
                // selected file
                FileStream fStream = new FileStream(filename,
                FileMode.Open, FileAccess.Read);
                BinaryReader br = new BinaryReader(fStream);

                // convert the file to a byte array
                byte[] data = br.ReadBytes((int)numBytes);

                // pass the byte array (file) and file name to the web service
                string sTmp = wser.UploadFile(data, strFile);

                //MessageBox.Show("File Upload Status: " + sTmp, "File Upload");
                // Display message if the file was too large to upload
                  MessageBox.Show("The file selected exceeds the size limit for uploads.", "File Size");
        catch (Exception ex)
            // display an error message to the user
            //MessageBox.Show(ex.Message.ToString(), "Upload Error");

Code on Web Service:
        public string UploadFile(byte[] f, string fileName)
                MemoryStream ms = new MemoryStream(f);
                FileStream fs = new FileStream(System.Web.Hosting.HostingEnvironment.MapPath
                            ("~/dataupload/") + fileName, FileMode.Create);

                ms = null;
                fs = null;
                return "OK";
            catch (Exception ex)
                return ex.Message.ToString();
Updated 18-Oct-11 1:54am
Nicholas Butler 18-Oct-11 6:53am    
How long does the transfer take before you get the error?
Md. Hasanuzzaman 23-Oct-11 23:58pm    
It takes 2 to 3 minute before getting error for a 1.6 MB file

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900