Troubleshooting ASPX file upload & parse not sending response to page
-
Monday, May 14, 2012 12:34 AM
I'm having an issue with a file upload in aspx never responding, even though the logic runs completely. Scenario:
simple aspx file upload with the following control:
ASPX: <asp:FileUpload ID="FileUploadContent" runat="server" /> <asp:Button ID="btnContentUpload" runat="server" Text="Upload" OnClick="btnContentUpload_Click" /> Code Behind: protected void btnContentUpload_Click(object sender, EventArgs e) { if (FileUploadContent.HasFile) { string FileName = Path.GetFileName(FileUploadContent.PostedFile.FileName); string FilePath = Server.MapPath("..\\App_Data\\" + FileName); FileUploadContent.SaveAs(FilePath); ParseFile(FilePath); } } protected void ParseFile(string filePath) { try { FileStream stream = new FileStream(filePath, FileMode.Open); StreamReader reader = new StreamReader(stream); while (!reader.EndOfStream) {
string line = reader.ReadLine();
// parse file
lblSuccessMssg.Text = "File uploaded successfully"; } catch (Exception ex) { lblErrorMssg.Text = "Error reading file. " + ex.Message; } } }
The problem I'm having is that the page never responds, and forever says "waiting on {server}..." in the status bar. You can go into the App_Data folder and see the file was copied, and you can open a new browser/tab to go to the accompanying report to see that the data was in fact uploaded, however the upload page itself never responds.
Now, this issue is only happening on the clients end, in all browsers. I have not been able to reproduce the issue myself, so I am wondering what probable causes there might be to troubleshoot.
EDIT: Show reader.ReadLine() so people don't think I have an infinite loop.
- Edited by Justin D Funk Monday, May 14, 2012 12:38 PM
- Moved by Mike FengMicrosoft Contingent Staff Monday, May 21, 2012 11:27 AM Asp.net (From:.NET Base Class Library)
All Replies
-
Monday, May 14, 2012 7:58 AMI think the problem is in the ParseFile, that never ends. What action do you perform in the while loop?
Marco Minerva [MCPD]
Blog: http://blogs.ugidotnet.org/marcom
Twitter: @marcominerva -
Monday, May 14, 2012 12:36 PM
If it never ended, I wouldn't get a response on my system. I commented out the logic because it's proprietary and irrelevant. However for the sake of satisfying the question, the first line is
string line = reader.ReadLine();
-
Monday, May 14, 2012 12:49 PMTo make a simple test, instead of read a single line in each iteration of the while loop, use the File.ReadAllLines methods to get the array of all lines in file.
Marco Minerva [MCPD]
Blog: http://blogs.ugidotnet.org/marcom
Twitter: @marcominerva -
Monday, May 14, 2012 1:26 PMIs there any compelling reason to do that, or is it just a guess? If I were able to reproduce the error I would give it a shot, however in this scenario I'd rather not rewrite all my code without good cause since it runs fine on my machine and the issue only occurs on the clients test server. I was thinking more along the lines of what web.config/IIS settings might be coming into play that could cause it. Maybe something related to timeouts or upload sizes? Though I do have it wrapped in a try/catch and it's not generating an error message either.
-
Monday, May 14, 2012 2:53 PM
As I have written, my suggestion is to make a test that can help identify the cause of the problem.
Marco Minerva [MCPD]
Blog: http://blogs.ugidotnet.org/marcom
Twitter: @marcominerva -
Tuesday, May 15, 2012 9:12 AM
Hi Justin,
To find the cause, please try to test it, so far, we cannot guess what is the exactly reason. So test is very important.
In addition, for asp.net issue, you can try to post it on http://forums.asp.net/
Have a nice day.
Ghost,
Call me ghost for short, Thanks
To get the better answer, it should be a better question.- Proposed As Answer by Mike FengMicrosoft Contingent Staff Monday, May 21, 2012 11:27 AM

