SaveAs或手工编写FileUpload

SaveAs或手工编写FileUpload

本文介绍了上传文件:FileUpload.SaveAs或手工编写FileUpload.FileBytes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用文件上传控件,请解释一下上传文件的以下两种方法之间的区别:

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

1。使用 FileUpload.SaveAs()方法:

1. Using the FileUpload.SaveAs() method:

fileUploadControl.SaveAs(path)

2。写一个字节数组到磁盘从 FileUpload.FileBytes 使用 File.WriteAllBytes()

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?

推荐答案

这些都具有不同的用途。
另存为,您可以保存为文件,直接而 WriteAllBytes 给你的内容的字节数组。

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.

我会使用 FileUpload.FileBytes 当我要访问的字节直接在内存中, fileUploadControl.SaveAs 时所有我想要做的就是将文件写入到磁盘中。

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.

这篇关于上传文件:FileUpload.SaveAs或手工编写FileUpload.FileBytes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 05:45