• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1151
  • Last Modified:

HttpPostedFile SaveAs method is corrupting file

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
mda11
Asked:
mda11
  • 4
  • 4
1 Solution
 
ventaurCommented:
What are the specs of the remote server? Specifically, is it a Windows box (what version) or something else?
0
 
mda11Author Commented:
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
 
ventaurCommented:
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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
mda11Author Commented:
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
 
ventaurCommented:
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
 
mda11Author Commented:
Thanks Ventaur, I'll start chasing up my provide. Cheers Mark
0
 
mda11Author Commented:
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
 
ventaurCommented:
Thanks for the update. I'm glad you got it resolved.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now