保存上传的文件 - 使用
我已经使用 FileUpload 控件上传了一个文件。我已经获得了路径和所有内容,我想将图像保存到服务器。我不想使用 SaveAs() 方法。 我想知道有没有办法用using语句保存文件?
I've uploaded a file with the FileUpload control. I've got the path and everything and I would like to save the image to the server. I don't want to use the SaveAs() method.
I wonder, is there a way to save the file with using-statement?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
查看 http://msdn.microsoft.com/en-us /library/system.io.filestream.aspx。您应该能够将数据流式传输到在永久存储中创建的新文件中。或者只是从您所说的已有的 tmp 路径执行复制操作。
http://msdn。 microsoft.com/en-us/library/system.io.file.copy(v=vs.71).aspx
Check out http://msdn.microsoft.com/en-us/library/system.io.filestream.aspx. You should be able to stream the data into a new file created in permanent storage. Or just do a copy operation from the tmp path you said you already have.
http://msdn.microsoft.com/en-us/library/system.io.file.copy(v=vs.71).aspx
您可以使用 StreamReader 从文件上传中读取文件,并使用 StreamWriter 类通过 Server.MapPath() 函数将其写入您的服务器(您的服务器绝对路径)
You can use StreamReader to read the file from file upload and use StreamWriter class to write it to your server with Server.MapPath() function(ur server absolute path)
您有 FileUpload.FileBytes 方法返回上传文件的字节数组或使用 FileUpload.PostedFile.InputStream 属性获取上传文件的流。
You have FileUpload.FileBytes method which returns array of bytes of uploaded file or use
FileUpload.PostedFile.InputStream
property to get stream of uploaded file.试试这个
fl.FileBytes
获取使用 FileUpload 控件指定的文件中的字节数组。
Try this
fl.FileBytes
Gets an array of the bytes in a file that is specified by using a FileUpload control.