Uploading files: FileUpload.SaveAs or manually writing FileUpload.FileBytes

别等时光非礼了梦想. 提交于 2020-01-05 04:36:29

问题


Using the FileUpload control, please explain the difference between the following two methods of uploading file:

1. Using the FileUpload.SaveAs() method:

fileUploadControl.SaveAs(path)

2. Writing a byte array to disk from FileUpload.FileBytes using File.WriteAllBytes():

File.WriteAllBytes(path, fileUploadControl.FileBytes);

How would these compare when uploading large files?


回答1:


These both have different purposes.
SaveAs lets you save as a file directly while WriteAllBytes gives you a byte array of contents.

Your file upload control will receive the bytes only after the file has been uploaded by the client, so there will be no difference in upload speeds.

A byte array is a value-type, so if you are passing copies of that around, note that it will create copies in memory whenever you pass it to functions.

I would use FileUpload.FileBytes when I want to access the bytes directly in memory and fileUploadControl.SaveAs whenever all I want to do is write the file to disk.



来源:https://stackoverflow.com/questions/16436083/uploading-files-fileupload-saveas-or-manually-writing-fileupload-filebytes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!