?
Solved

HttpPostedFile SaveAs method is corrupting file

Posted on 2011-04-19
8
Medium Priority
?
1,128 Views
Last Modified: 2012-08-13
I have a vb.net webpage with a Flash file uploader. When I use the HttpPostedFile.SaveAs method and save the file to a folder on the local drive of the web server, the file saves correctly and is readable by Excel. When the same file is saved to a remote server in the workgroup the Excel file is corrupted and cannot be opened. The file size for the original Excel spreadsheet is 3.89 megs, when it arrives on the remote server the file size is 3.51 megs. The Flash Uploader reports no errors, and the webpage reports no errors. The whole file upload and saving process is seamless and reports no errors.
Originally I was having a problem with Symantec Endpoint Protection software, in debug mode vb.net would report the network connection being unavailable. Since updating the Symantec software I don't have the network connection timing out, but still have the file corruption problem.
Any help would be most appreciated as I'm confused and frustrated. Thanks
0
Comment
Question by:mda11
  • 4
  • 4
8 Comments
 
LVL 6

Expert Comment

by:ventaur
ID: 35432595
What are the specs of the remote server? Specifically, is it a Windows box (what version) or something else?
0
 

Author Comment

by:mda11
ID: 35432927
The remote server is a Windows 2003 box, the same as the web server. The machines are hosted and are in a workgroup environment. I have an admin userid which I use across the 2 machines so as to copy the file, the userid has read/write permissions. Thank
0
 
LVL 6

Expert Comment

by:ventaur
ID: 35433510
I suggest that you try a couple of quick experiments to track down where the real issue is.

First, use HttpPostedFile.SaveAs to save the file to the local hard drive again. Then, use File.Copy or File.Move to copy/move the file from the local drive to the remote server. Check the results of the file on the remote server.

Second, if you are saving the file to the remote server via a UNC path, try using a mapped drive instead. Likewise, if you are using a mapped drive, try using a UNC path. Depending on what version of .NET you are using, I remember an issue with UNC in one of the older Framework versions.


Also, you are really getting close to the default maximum upload size (which includes the other fields on the page; even view state). You may need to set the maxRequestLength attribute of the httpRuntime element in your config file soon. Note: this should not effect the problem you are having with the file you mentioned, since it is just under 4MB; the default max.
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 

Author Comment

by:mda11
ID: 35438528
I've carried out the tasks as you have outlined
HttpPostedFile.SaveAs to the local hard drive, which works well with no corruption.
File.Copy or File.Move works and the file is copied to the remote server, but it is happening very slowly, for a larger file I get the error 'The semaphore timeout period has expired.'  A Google search suggests a network, hardware device problem.
I used Windows Explorer to copy a file from the local hard drive to the network drive. The size of the file was 8megs, the time remaining kept bouncing around from 4mins, 40secs, 2mins, 30secs eventually it took 3mins to copy an 8meg file, which is way to long.
Given the boxes are in a hosted enviroment by one of the Telecom providers I don't know what action they can take to speed up the network connections or if I can do something myself.
But I can say I've had more sucess using the File.Move method rather than SaveAs.
0
 
LVL 6

Accepted Solution

by:
ventaur earned 2000 total points
ID: 35440461
My guess would be there is some misconfiguration with your private network (subnet issue perhaps) with your provider. Another possible issue is there is a bad hard drive on the remote server. Either way, your Google search sounds correct after performing the tests above.

Your provider should be accountable for remedying the situation. It is currently an unusable environment for you. I wish you luck getting it resolved.
0
 

Author Closing Comment

by:mda11
ID: 35440640
Thanks Ventaur, I'll start chasing up my provide. Cheers Mark
0
 

Author Comment

by:mda11
ID: 35473133
After logging a service call with the hosting provider, it turns out there was a problem, "The duplex setting on the switch was set incorrectly" who knew...
0
 
LVL 6

Expert Comment

by:ventaur
ID: 35475141
Thanks for the update. I'm glad you got it resolved.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question