传输是 MemoryStream 并没有用到io 保存才io
解决方案 »
- 这两个代码有区别吗?
- 导入Excel数据并插入数据库一个很奇怪的问题,贴出代码,大家帮帮我!
- 网址显示问题
- <%# DataBinder.Eval(Container.DataItem,"id")怎么绑定两个值啊??????????????
- 公司最近想買version control的軟件,但不知道哪個最適合我們.(看內容)
- 关于。NET中日历的问题
- asp/asp.net内部对象说明,session,request,..............等等
- 请问怎么在asp.net页面中的datagrid中的一个项能使用连接?
- 为什么我的修改有问题
- 完了,完了!是不是不会写存储过程的就不是合格的程序员呢?请大家讨论
- windows 2003 IIS6 ASP.NET操作文件夹无效
- The underlying provider failed on Open
System.IO.MemoryStream fs = file.InputStream; 能转?
下面加一句:
fs.Seek(0, SeekOrigin.Begin);试试
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Seek(0, SeekOrigin.Begin);
fs.Close();没用,出来的文件还是损坏的
额 好像唯一的区别就是 :
.\100吧主候选人.jpg different (E:\abc\100吧主候选人.jpg is more recent)但保存出来的文件确实是损坏的:
Stream fs = file.InputStream;
BinaryReader br = new BinaryReader(fs);
byte[] bytes = br.ReadBytes((Int32)fs.Length);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();
这一步的问题?
using (Stream output = File.OpenWrite("c:\temp\file.zip"))
using (Stream input = file.InputStream)
{
byte[] buffer = new byte[8192];
int bytesRead;
while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, bytesRead);
}
}
把上面的File.OpenWrite换成file.InputStreamhttp://stackoverflow.com/questions/12927932/file-upload-with-c-sharp-and-streaming
你去看看HttpWorkerRequest类吧,可以通过GetPreloadedEntityBody、ReadEntityBody方法在预加载阶段提前读取到客户端提交的数据,这里取出来的就是byte[],不过需要你自行从中分离出属于文件内容的部分
HttpPostedFile file = files[0];
int upPhotoLength = files.ContentLength;
byte[] PhotoArray = new Byte[upPhotoLength];
Stream PhotoStream = files.InputStream;
PhotoStream.Read(PhotoArray, 0, upPhotoLength);